Search in sources :

Example 56 with GradleVersion

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();
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) GradleVersion(com.android.ide.common.repository.GradleVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with GradleVersion

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();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 58 with GradleVersion

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();
}
Also used : Project(com.intellij.openapi.project.Project) NewVectorAssetStep(com.android.tools.idea.npw.assetstudio.wizard.NewVectorAssetStep) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GenerateVectorIconModel(com.android.tools.idea.npw.assetstudio.wizard.GenerateVectorIconModel) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion) GradleVersion(com.android.ide.common.repository.GradleVersion) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with GradleVersion

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;
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) IOException(java.io.IOException) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with GradleVersion

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);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) GradleVersion(com.android.ide.common.repository.GradleVersion) Module(com.intellij.openapi.module.Module)

Aggregations

GradleVersion (com.android.ide.common.repository.GradleVersion)77 File (java.io.File)25 Test (org.junit.Test)16 Module (com.intellij.openapi.module.Module)12 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)11 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)5 IOException (java.io.IOException)5 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)4 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)3 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)3 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)3 ZipFile (java.util.zip.ZipFile)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 Variant (com.android.builder.model.Variant)2 IDevice (com.android.ddmlib.IDevice)2 Revision (com.android.repository.Revision)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2