Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

适配 AGP4.2.2 #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 ")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> installOptions = variantData.scope.globalScope.extension.adbOptions.installOptions
Expand Down Expand Up @@ -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<String> installOptions = variantData.globalScope.extension.adbOptions.installOptions
Expand Down Expand Up @@ -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<String> installOptions = variantData.scope.globalScope.extension.adbOptions.installOptions
Expand Down