use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class ChooseActivityTypeStep method determineGradlePluginVersion.
/**
* Find the most appropriated Gradle Plugin version for the specified project.
* @param project If {@code null} (ie we are creating a new project) returns the recommended gradle version.
*/
@NotNull
private static String determineGradlePluginVersion(@Nullable Project project) {
String defaultGradleVersion = AndroidPluginGeneration.ORIGINAL.getLatestKnownVersion();
if (project == null) {
return defaultGradleVersion;
}
GradleVersion versionInUse = GradleUtil.getAndroidGradleModelVersionInUse(project);
if (versionInUse != null) {
return versionInUse.toString();
}
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(project);
GradleVersion pluginVersion = (androidPluginInfo == null) ? null : androidPluginInfo.getPluginVersion();
return (pluginVersion == null) ? defaultGradleVersion : pluginVersion.toString();
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class BuildSignedApkTest method openAndSignUsingV1AndV2.
@Test
public void openAndSignUsingV1AndV2() 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(true).clickFinish();
// We should verify that a V2 signature is 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();
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class NewVectorAssetAction method createWizard.
@Nullable
@Override
protected ModelWizard createWizard(@NotNull AndroidFacet facet) {
Module module = facet.getModule();
Project project = module.getProject();
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
AndroidVersion minSdkVersion = androidModel.getMinSdkVersion();
String version = androidModel.getAndroidProject().getModelVersion();
GradleVersion revision = GradleVersion.parse(version);
if (revision.compareIgnoringQualifiers(VECTOR_ASSET_GENERATION_REVISION) < 0 && (minSdkVersion == null || minSdkVersion.getApiLevel() < VECTOR_DRAWABLE_API_LEVEL)) {
Messages.showErrorDialog(project, ERROR_MESSAGE, ERROR_TITLE);
return null;
}
}
ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
wizardBuilder.addStep(new NewVectorAssetStep(new GenerateVectorIconModel(facet), facet));
return wizardBuilder.build();
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class GradleVersions method getGradleVersion.
@Nullable
public GradleVersion getGradleVersion(@NotNull Project project) {
GradleVersion gradleVersion = GradleSyncState.getInstance(project).getSummary().getGradleVersion();
if (gradleVersion != null) {
// The version of Gradle used is retrieved one of the Gradle models. If that fails, we try to deduce it from the project's Gradle
// settings.
GradleVersion revision = GradleVersion.tryParse(removeTimestampFromGradleVersion(gradleVersion.toString()));
if (revision != null) {
return revision;
}
}
GradleProjectSettings gradleSettings = mySettingsFinder.findGradleProjectSettings(project);
if (gradleSettings != null) {
DistributionType distributionType = gradleSettings.getDistributionType();
if (distributionType == DEFAULT_WRAPPED) {
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
try {
String wrapperVersion = gradleWrapper.getGradleVersion();
if (wrapperVersion != null) {
return GradleVersion.tryParse(removeTimestampFromGradleVersion(wrapperVersion));
}
} catch (IOException e) {
Logger.getInstance(getClass()).info("Failed to read Gradle version in wrapper", e);
}
}
} else if (distributionType == LOCAL) {
String gradleHome = gradleSettings.getGradleHome();
if (isNotEmpty(gradleHome)) {
File gradleHomePath = new File(gradleHome);
return getGradleVersion(gradleHomePath);
}
}
}
return null;
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class Projects method storePluginVersionsPerModule.
public static void storePluginVersionsPerModule(@NotNull Project project) {
Map<String, GradleVersion> pluginVersionsPerModule = Maps.newHashMap();
for (Module module : ModuleManager.getInstance(project).getModules()) {
AndroidModuleModel model = AndroidModuleModel.get(module);
if (model != null) {
GradleFacet facet = GradleFacet.getInstance(module);
if (facet != null) {
GradleVersion modelVersion = model.getModelVersion();
if (modelVersion != null) {
pluginVersionsPerModule.put(facet.getConfiguration().GRADLE_PROJECT_PATH, modelVersion);
}
}
}
}
project.putUserData(PLUGIN_VERSIONS_BY_MODULE, pluginVersionsPerModule);
}
Aggregations