diff --git a/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/QigsawAppBasePlugin.groovy b/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/QigsawAppBasePlugin.groovy index 17b7568..4c90be8 100644 --- a/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/QigsawAppBasePlugin.groovy +++ b/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/QigsawAppBasePlugin.groovy @@ -64,6 +64,8 @@ class QigsawAppBasePlugin extends QigsawPlugin { def android = project.extensions.android //create ComponentInfo.class to record Android Component of dynamic features. SplitComponentTransform componentTransform = new SplitComponentTransform(project) + File splitManifestParentDir = project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/${QIGSAW}/split-outputs/manifests") + componentTransform.splitManifestParentDir = splitManifestParentDir SplitResourcesLoaderTransform resourcesLoaderTransform = new SplitResourcesLoaderTransform(project, true) android.registerTransform(componentTransform) @@ -87,8 +89,6 @@ class QigsawAppBasePlugin extends QigsawPlugin { dynamicFeaturesNames.add(splitProject.name) } componentTransform.dynamicFeatureNames = dynamicFeaturesNames - File splitManifestParentDir = project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/${QIGSAW}/split-outputs/manifests") - componentTransform.splitManifestParentDir = splitManifestParentDir android.applicationVariants.all { ApplicationVariant baseVariant -> if (baseVariant.versionName == null || baseVariant.applicationId == null) { throw new GradleException("versionName and applicationId must be set in ${project.name}/build.gradle ") @@ -450,7 +450,7 @@ class QigsawAppBasePlugin extends QigsawPlugin { Task splitAssemble = AGPCompat.getAssemble(splitVariant) ProcessSplitApkTask processSplitApk = splitProject.tasks.create("processSplitApk${splitVariant.name.capitalize()}", ProcessSplitApkTask) processSplitApk.apkSigner = apkSigner - processSplitApk.aapt2File = new File(AGPCompat.getAapt2FromMavenCompat(baseVariant), SdkConstants.FN_AAPT2) + processSplitApk.aapt2File = new File(AGPCompat.getAapt2FromMavenCompat(baseVariant,splitProject), SdkConstants.FN_AAPT2) processSplitApk.releaseSplitApk = QigsawSplitExtensionHelper.isReleaseSplitApk(baseProject) processSplitApk.restrictWorkProcessesForSplits = QigsawSplitExtensionHelper.getRestrictWorkProcessesForSplits(baseProject) processSplitApk.minApiLevel = minApiLevel diff --git a/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/internal/tool/AGPCompat.groovy b/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/internal/tool/AGPCompat.groovy index f7881dc..3e1a67b 100644 --- a/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/internal/tool/AGPCompat.groovy +++ b/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/internal/tool/AGPCompat.groovy @@ -25,8 +25,11 @@ package com.iqiyi.qigsaw.buildtool.gradle.internal.tool import com.android.SdkConstants +import com.android.build.gradle.BaseExtension import com.android.build.gradle.api.ApplicationVariant +import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.scope.GlobalScope +import com.android.build.gradle.internal.variant.BaseVariantData import com.android.utils.ILogger import org.gradle.api.GradleException import org.gradle.api.Project @@ -51,16 +54,26 @@ class AGPCompat { return mergedAssetsOutputDir } - static File getAapt2FromMavenCompat(def variant) { + static File getAapt2FromMavenCompat(def variant, def splitProject) { + + def versionAGP = VersionNumber.parse(getAndroidGradlePluginVersionCompat()) + if (versionAGP >= VersionNumber.parse("4.2.0")) { + return splitProject.getPlugins() + .getPlugin(com.android.build.gradle.internal.plugins.DynamicFeaturePlugin.class) + .projectServices + .aapt2FromMaven + .aapt2Directory + .singleFile + } + try { Class class_Aapt2MavenUtils = Class.forName("com.android.build.gradle.internal.res.Aapt2MavenUtils") Method method_getAapt2FromMaven = class_Aapt2MavenUtils.getDeclaredMethod("getAapt2FromMaven", GlobalScope) method_getAapt2FromMaven.setAccessible(true) - def versionAGP = VersionNumber.parse(getAndroidGradlePluginVersionCompat()) def aapt2 - if(versionAGP >= VersionNumber.parse("4.1.0")){ + if (versionAGP >= VersionNumber.parse("4.1.0")) { aapt2 = method_getAapt2FromMaven.invoke(null, variant.variantData.globalScope).singleFile - }else{ + } else { aapt2 = method_getAapt2FromMaven.invoke(null, variant.variantData.scope.globalScope).singleFile } return aapt2 @@ -84,7 +97,7 @@ class AGPCompat { try { if (versionAGP >= VersionNumber.parse("4.1.0")) { manifestOutputBaseDir = processManifestTask.multiApkManifestOutputDirectory.get().getAsFile().getAbsolutePath() - }else{ + } else { manifestOutputBaseDir = processManifestTask.manifestOutputDirectory.asFile.get() } } catch (Throwable ignored) { @@ -110,7 +123,7 @@ class AGPCompat { if (versionAGP >= VersionNumber.parse("4.1.0")) { bundleManifestDir = processManifestTask.bundleManifest.get().getAsFile() - }else{ + } else { bundleManifestDir = processManifestTask.bundleManifestOutputDirectory } } catch (Throwable e) { @@ -292,4 +305,33 @@ class AGPCompat { throw new GradleException("Qigsaw has not adapt this AGP version yet, class 'com.android.builder.testing.api.DeviceProvider' is not found!") } + static File getAdbExecutable(BaseVariantData variantData, Project project) { + File adbExecutable = null + def versionAGP = VersionNumber.parse(AGPCompat.getAndroidGradlePluginVersionCompat()) + if (versionAGP < VersionNumber.parse("4.1.0")) {//[ , 4.1.0) + try { + adbExecutable = variantData.scope.globalScope.sdkHandler.sdkInfo.adb + } catch (Throwable ignored) { + } + try { + adbExecutable = variantData.scope.globalScope.sdkComponents.adbExecutableProvider.get() + } catch (Throwable e) { + } + } else if (versionAGP < VersionNumber.parse("4.2.0")) {//[4.1.0 , 4.2.0) + try { + adbExecutable = variantData.globalScope.sdkComponents.get().adbExecutableProvider.get().getAsFile() + } catch (Throwable ignored) { + } + } else {//[4.2.0 , +] + try { + adbExecutable = project.getExtensions().getByType(BaseExtension.class).adbExecutable + } catch (Throwable ignored) { + } + } + if (adbExecutable == null) { + throw new GradleException("> Task :Qigsaw don't support current AGP version, adbExecutable is null!") + } + return adbExecutable + } + } diff --git a/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/task/QigsawInstallTask.groovy b/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/task/QigsawInstallTask.groovy index d3b3036..aa93d76 100644 --- a/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/task/QigsawInstallTask.groovy +++ b/buildSrc/src/main/groovy/com/iqiyi/qigsaw/buildtool/gradle/task/QigsawInstallTask.groovy @@ -69,19 +69,7 @@ class QigsawInstallTask extends DefaultTask { } void installAboveAGP4() { - File adbExecutable = null - try { - adbExecutable = variantData.scope.globalScope.sdkHandler.sdkInfo.adb - } catch (Throwable ignored) { - try { - adbExecutable = variantData.scope.globalScope.sdkComponents.adbExecutableProvider.get() - } catch (Throwable e) { - // - } - } - if (adbExecutable == null) { - throw new GradleException("> Task :Qigsaw don't support current AGP version, adbExecutable is null!") - } + File adbExecutable = AGPCompat.getAdbExecutable(variantData, project) int timeOutInMs = variantData.scope.globalScope.extension.adbOptions.timeOutInMs String projectName = variantData.scope.globalScope.project.name Collection installOptions = variantData.scope.globalScope.extension.adbOptions.installOptions @@ -109,14 +97,7 @@ class QigsawInstallTask extends DefaultTask { } void installAboveAGP41() { - File adbExecutable = null - try { - adbExecutable = variantData.globalScope.sdkComponents.get().adbExecutableProvider.get().getAsFile() - } catch (Throwable ignored) { - } - if (adbExecutable == null) { - throw new GradleException("> Task :Qigsaw don't support current AGP version, adbExecutable is null!") - } + File adbExecutable = AGPCompat.getAdbExecutable(variantData, project) int timeOutInMs = variantData.globalScope.extension.adbOptions.timeOutInMs String projectName = project.name Collection installOptions = variantData.globalScope.extension.adbOptions.installOptions @@ -145,19 +126,7 @@ class QigsawInstallTask extends DefaultTask { void installBelowAGP4() { - File adbExecutable = null - try { - adbExecutable = variantData.scope.globalScope.sdkHandler.sdkInfo.adb - } catch (Throwable ignored) { - try { - adbExecutable = variantData.scope.globalScope.sdkComponents.adbExecutableProvider.get() - } catch (Throwable e) { - // - } - } - if (adbExecutable == null) { - throw new GradleException("> Task :Qigsaw don't support current AGP version, adbExecutable is null!") - } + File adbExecutable = AGPCompat.getAdbExecutable(variantData, project) int timeOutInMs = variantData.scope.globalScope.extension.adbOptions.timeOutInMs String projectName = variantData.scope.globalScope.project.name Collection installOptions = variantData.scope.globalScope.extension.adbOptions.installOptions