From bc1069cff6395ace92c8715abe148c83ec10a5ba Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 20 Apr 2021 18:24:31 +0800 Subject: [PATCH] Support gradle 6.5, android-gradle-plugin 4.1.3 --- build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../groovy/io/ivan/pipe/GradlePlugin.groovy | 8 ++-- src/main/groovy/io/ivan/pipe/Task.groovy | 48 ++++++++----------- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index f8e3a3d..48cbd00 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'com.github.1van' -version '1.0.0' +version '1.1.0' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -20,7 +20,7 @@ repositories { dependencies { compile gradleApi() compile localGroovy() - compile 'com.android.tools.build:gradle:3.6.3' + compile 'com.android.tools.build:gradle:4.1.3' } gradlePlugin { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c238640..8c43a6c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Mon Apr 27 15:52:21 CST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/main/groovy/io/ivan/pipe/GradlePlugin.groovy b/src/main/groovy/io/ivan/pipe/GradlePlugin.groovy index 49e5e79..309e862 100755 --- a/src/main/groovy/io/ivan/pipe/GradlePlugin.groovy +++ b/src/main/groovy/io/ivan/pipe/GradlePlugin.groovy @@ -1,9 +1,9 @@ package io.ivan.pipe -import com.android.build.gradle.api.BaseVariant +import com.android.build.gradle.internal.api.ApplicationVariantImpl +import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.ProjectConfigurationException class GradlePlugin implements Plugin { @@ -12,7 +12,7 @@ class GradlePlugin implements Plugin { @Override void apply(Project project) { if (!project.plugins.hasPlugin("com.android.application")) { - throw new ProjectConfigurationException("[pipe]: plugin 'com.android.application' must be apply", null) + throw new GradleException("[pipe]: plugin 'com.android.application' must be apply") } applyExtension(project) applyTask(project) @@ -24,7 +24,7 @@ class GradlePlugin implements Plugin { private void applyTask(Project project) { project.afterEvaluate { - project.android.applicationVariants.all { BaseVariant variant -> + project.android.applicationVariants.all { ApplicationVariantImpl variant -> def variantName = variant.name.capitalize() Task task = project.tasks.create("pipeAssemble${variantName}", Task) as Task diff --git a/src/main/groovy/io/ivan/pipe/Task.groovy b/src/main/groovy/io/ivan/pipe/Task.groovy index 1430c98..6f695ff 100755 --- a/src/main/groovy/io/ivan/pipe/Task.groovy +++ b/src/main/groovy/io/ivan/pipe/Task.groovy @@ -1,40 +1,38 @@ package io.ivan.pipe -import com.android.build.gradle.api.BaseVariant +import com.android.build.gradle.internal.api.ApplicationVariantImpl import com.android.builder.model.SigningConfig import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Project -import org.gradle.api.ProjectConfigurationException import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction - class Task extends DefaultTask { private static final String DOT_APK = ".apk" private static final String PROTECT_TYPE = "360" @Input - public BaseVariant variant + public ApplicationVariantImpl variant @Input public Project targetProject - def jiaguJava - def jiaguFile - def jiaguCommand + String jiaguJava + String jiaguFile + String jiaguCommand - def apksignerFile - def apksignerCommand + String apksignerFile + String apksignerCommand - def vasDollyFile - def vasDollyCommand + String vasDollyFile + String vasDollyCommand - def apkFilePath - def baseApkFilePath - def buildPath - def tempApkPath - def tempDirPath + String apkFilePath + String baseApkFilePath + String buildPath + String tempApkPath + String tempDirPath void setup() { def extension = Extension.getConfig(targetProject) @@ -76,29 +74,21 @@ class Task extends DefaultTask { private void checkParameter() { def extension = Extension.getConfig(project) if (StringUtils.isEmpty(extension.apkOutputFolder)) { - throw new ProjectConfigurationException("[pipe]: apkOutputFolder is not configured!", null) + throw new GradleException("[pipe]: apkOutputFolder is not configured , please check it !") } if (StringUtils.isEmpty(extension.channelFile)) { - throw new ProjectConfigurationException("[pipe]: channelFile is not configured!", null) + throw new GradleException("[pipe]: channelFile is not configured , please check it !") } if (StringUtils.isEmpty(extension.toolsPath)) { - throw new ProjectConfigurationException("[pipe]: toolsPath is not configured!", null) + throw new GradleException("[pipe]: toolsPath is not configured , please check it !") } if (getSigningConfig() == null) { - throw new GradleException("[pipe]: SigningConfig is null , please check it") + throw new GradleException("[pipe]: SigningConfig is null , please check it !") } } SigningConfig getSigningConfig() { - //return mVariant.buildType.signingConfig == null ? mVariant.mergedFlavor.signingConfig : mVariant.buildType.signingConfig - SigningConfig config = null - try { - config = variant.variantData.variantConfiguration.signingConfig - } catch (Throwable e) { - config = variant.apkVariantData.variantConfiguration.signingConfig - // e.printStackTrace() - } - return config + return variant.buildType.signingConfig == null ? variant.mergedFlavor.signingConfig : variant.buildType.signingConfig } private void initPath(File apkFile) {