use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class AndroidGradleJavaProjectModelModifier method findNewExternalDependency.
@Nullable
private static ArtifactDependencySpec findNewExternalDependency(@NotNull Library library, @NotNull AndroidModuleModel androidModel) {
GradleVersion modelVersion = androidModel.getModelVersion();
JavaLibrary matchedLibrary = null;
for (BaseArtifact testArtifact : androidModel.getTestArtifactsInSelectedVariant()) {
matchedLibrary = findMatchedLibrary(library, testArtifact, modelVersion);
if (matchedLibrary != null) {
break;
}
}
if (matchedLibrary == null) {
Variant selectedVariant = androidModel.getSelectedVariant();
matchedLibrary = findMatchedLibrary(library, selectedVariant.getMainArtifact(), modelVersion);
}
if (matchedLibrary == null) {
return null;
}
// TODO use getRequestedCoordinates once the interface is fixed.
MavenCoordinates coordinates = matchedLibrary.getResolvedCoordinates();
if (coordinates == null) {
return null;
}
return new ArtifactDependencySpec(coordinates.getArtifactId(), coordinates.getGroupId(), coordinates.getVersion());
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class AndroidContentEntriesSetup method addGeneratedSourceFolders.
private void addGeneratedSourceFolders(@NotNull BaseArtifact artifact, @NotNull List<ContentEntry> contentEntries, boolean isTest) {
JpsModuleSourceRootType sourceType = getSourceType(isTest);
GradleVersion modelVersion = myAndroidModel.getModelVersion();
if (artifact instanceof AndroidArtifact || (modelVersion != null && modelVersion.compareIgnoringQualifiers("1.2") >= 0)) {
// getGeneratedSourceFolders used to be in AndroidArtifact only.
Collection<File> generatedSourceFolders = getGeneratedSourceFolders(artifact);
//noinspection ConstantConditions - this returned null in 1.2
if (generatedSourceFolders != null) {
addSourceFolders(generatedSourceFolders, contentEntries, sourceType, true);
}
}
if (artifact instanceof AndroidArtifact) {
sourceType = getResourceSourceType(isTest);
AndroidArtifact androidArtifact = (AndroidArtifact) artifact;
addSourceFolders(androidArtifact.getGeneratedResourceFolders(), contentEntries, sourceType, true);
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class EncodingValidationStrategy method validate.
@Override
void validate(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
GradleVersion modelVersion = (androidModel.getModelVersion());
if (modelVersion != null) {
boolean isOneDotTwoOrNewer = modelVersion.compareIgnoringQualifiers(myOneDotTwoPluginVersion) >= 0;
// Verify that the encoding in the model is the same as the encoding in the IDE's project settings.
Charset modelEncoding = null;
if (isOneDotTwoOrNewer) {
try {
AndroidProject androidProject = androidModel.getAndroidProject();
modelEncoding = Charset.forName(androidProject.getJavaCompileOptions().getEncoding());
} catch (UnsupportedCharsetException ignore) {
// It's not going to happen.
}
}
if (myMismatchingEncoding == null && modelEncoding != null && myProjectEncoding.compareTo(modelEncoding) != 0) {
myMismatchingEncoding = modelEncoding.displayName();
}
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class GradleSignStep method _init.
@Override
public void _init() {
myAndroidModel = AndroidModuleModel.get(myWizard.getFacet());
PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
String lastSelectedBuildType = properties.getValue(PROPERTY_BUILD_TYPE);
myBuildTypeComboModel.removeAllElements();
Set<String> buildTypes = myAndroidModel == null ? Collections.<String>emptySet() : myAndroidModel.getBuildTypes();
for (String buildType : buildTypes) {
myBuildTypeComboModel.addElement(buildType);
if ((lastSelectedBuildType == null && buildType.equals("release")) || buildType.equals(lastSelectedBuildType)) {
myBuildTypeComboModel.setSelectedItem(buildType);
}
}
myFlavorsListModel.clear();
List<String> productFlavors;
if (myAndroidModel == null || myAndroidModel.getProductFlavors().isEmpty()) {
productFlavors = Collections.emptyList();
} else {
// if there are multiple flavors, we want the merged flavor list
Set<String> mergedFlavors = Sets.newHashSet();
for (Variant v : myAndroidModel.getAndroidProject().getVariants()) {
mergedFlavors.add(ExportSignedPackageWizard.getMergedFlavorName(v));
}
productFlavors = Lists.newArrayList(mergedFlavors);
Collections.sort(productFlavors);
}
TIntArrayList lastSelectedIndices = new TIntArrayList(productFlavors.size());
String[] flavors = properties.getValues(PROPERTY_FLAVORS);
Set<String> lastSelectedFlavors = flavors == null ? Collections.<String>emptySet() : Sets.newHashSet(flavors);
for (int i = 0; i < productFlavors.size(); i++) {
String flavor = productFlavors.get(i);
myFlavorsListModel.addElement(flavor);
if (lastSelectedFlavors.contains(flavor)) {
lastSelectedIndices.add(i);
}
}
myFlavorsList.setSelectedIndices(lastSelectedIndices.toNativeArray());
String lastApkFolderPath = properties.getValue(PROPERTY_APK_PATH);
File lastApkFolder;
if (lastApkFolderPath != null) {
lastApkFolder = new File(lastApkFolderPath);
} else {
if (myAndroidModel == null) {
lastApkFolder = VfsUtilCore.virtualToIoFile(myWizard.getProject().getBaseDir());
} else {
lastApkFolder = myAndroidModel.getRootDirPath();
}
}
myApkPathField.setText(lastApkFolder.getAbsolutePath());
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
myApkPathField.addBrowseFolderListener("Select APK Destination Folder", null, myWizard.getProject(), descriptor);
GradleVersion modelVersion = null;
if (myAndroidModel != null) {
modelVersion = myAndroidModel.getModelVersion();
}
boolean enabled = modelVersion != null && modelVersion.compareIgnoringQualifiers(MIN_SIGNATURE_SELECTION_VERSION) >= 0;
myV1JarSignatureCheckBox.setEnabled(enabled);
myV1JarSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V1_SIGN));
myV2FullAPKSignatureCheckBox.setEnabled(enabled);
myV2FullAPKSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V2_SIGN));
// Set HTML label here; the visual editor does not like the " " part so set the text here.
mySignatureHelpLabel.setText("<html><a href=\"\">Signature Help</a></html>");
mySignatureHelpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mySignatureHelpLabel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
URI uri;
try {
uri = new URI("http://developer.android.com/about/versions/nougat/android-7.0.html#apk_signature_v2");
} catch (URISyntaxException ex) {
throw new AssertionError(ex);
}
try {
desktop.browse(uri);
} catch (IOException ex) {
LOG.error("Failed to open URI '" + uri + "'", ex);
}
}
}
}
});
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class BuildSignedApkTest method openAndSignUsingV1Only.
@Test
public void openAndSignUsingV1Only() throws IOException {
GradleVersion latestVersion = GradleVersion.parse(SdkConstants.GRADLE_PLUGIN_LATEST_VERSION);
assume().that(latestVersion.compareIgnoringQualifiers(GradleSignStep.MIN_SIGNATURE_SELECTION_VERSION)).isAtLeast(0);
File jksFile = new File(myTemporaryFolder.getRoot(), "jks");
File dstFolder = myTemporaryFolder.newFolder("dst");
guiTest.importSimpleApplication().openFromMenu(BuildSignedApkDialogKeystoreStepFixture::find, "Build", "Generate Signed APK...").createNew().keyStorePath(jksFile.getAbsolutePath()).password("passwd").passwordConfirm("passwd").alias("key").keyPassword("passwd2").keyPasswordConfirm("passwd2").validity("3").firstAndLastName("Android Studio").organizationalUnit("Android").organization("Google").cityOrLocality("Mountain View").stateOrProvince("California").countryCode("US").clickOk().keyStorePassword("passwd").keyAlias("key").keyPassword("passwd2").clickNext().apkDestinationFolder(dstFolder.getAbsolutePath()).setV1SignatureEnabled(true).setV2SignatureEnabled(false).clickFinish();
// We should verify that a V2 signature is not present, but that is hard to do here.
File[] apks = dstFolder.listFiles();
assertThat(apks).hasLength(1);
File apk = apks[0];
try (ZipFile zf = new ZipFile(apk)) {
assertThat(zf.getEntry("META-INF/CERT.SF")).isNotNull();
}
}
Aggregations