Skip to content

Commit

Permalink
fix exception when assemble release, generated proguard will merge co…
Browse files Browse the repository at this point in the history
…nsumer proguard.txt
  • Loading branch information
kezong committed Dec 13, 2020
1 parent 1f655a7 commit 19a079f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions source/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ publish {
userOrg = 'kezong'
groupId = 'com.kezong'
artifactId = 'fat-aar'
publishVersion = '1.3.0'
desc = 'Gradle plugin for merging dependencies applies to gradle plugin version 3.+'
publishVersion = '1.3.1'
desc = 'A gradle plugin that merge dependencies into the final aar file works with AGP 3.+'
website = 'https://github.com/kezong/fat-aar-android'
}

53 changes: 39 additions & 14 deletions source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class VariantProcessor {
processResources()
processAssets()
processJniLibs()
processProguardTxt()
processConsumerProguard()
processGenerateProguard()
processDataBinding(bundleTask)
processRClasses(transform, bundleTask)
}
Expand Down Expand Up @@ -419,18 +420,6 @@ class VariantProcessor {
*/
private void processClassesAndJars(TaskProvider<Task> bundleTask) {
boolean isMinifyEnabled = mVariant.getBuildType().isMinifyEnabled()
if (isMinifyEnabled) {
//merge proguard file
for (archiveLibrary in mAndroidArchiveLibraries) {
List<File> thirdProguardFiles = archiveLibrary.proguardRules
for (File file : thirdProguardFiles) {
if (file.exists()) {
FatUtils.logInfo('add proguard file: ' + file.absolutePath)
mProject.android.getDefaultConfig().proguardFile(file)
}
}
}
}

TaskProvider syncLibTask = mProject.tasks.named(mVersionAdapter.getSyncLibJarsTaskPath())
TaskProvider extractAnnotationsTask = mProject.tasks.named("extract${mVariant.name.capitalize()}Annotations")
Expand Down Expand Up @@ -537,7 +526,7 @@ class VariantProcessor {
/**
* merge proguard.txt
*/
private void processProguardTxt() {
private void processConsumerProguard() {
String mergeTaskName = 'merge' + mVariant.name.capitalize() + 'ConsumerProguardFiles'
TaskProvider mergeFileTask = mProject.tasks.named(mergeTaskName)
if (mergeFileTask == null) {
Expand Down Expand Up @@ -566,4 +555,40 @@ class VariantProcessor {
}
}
}

/**
* merge consumer proguard to generate proguard
* @since AGP 3.6
*/
private void processGenerateProguard() {
TaskProvider mergeGenerateProguardTask
try {
String mergeName = 'merge' + mVariant.name.capitalize() + 'GeneratedProguardFiles'
mergeGenerateProguardTask = mProject.tasks.named(mergeName)
} catch(Exception ignore) {
return
}

mergeGenerateProguardTask.configure {
dependsOn(mExplodeTasks)
doLast {
try {
Collection<File> files = mAndroidArchiveLibraries.stream().map { it.proguardRules }.collect()
File of
if (outputFile instanceof File) {
of = outputFile
} else {
// RegularFileProperty.class
of = outputFile.get().asFile
}
FatUtils.mergeFiles(files, of)
} catch (Exception e) {
FatUtils.logAnytime(("If you see this error message, please submit issue to " +
"https://github.com/kezong/fat-aar-android/issues with version of AGP and Gradle. Thank you.")
)
e.printStackTrace()
}
}
}
}
}

0 comments on commit 19a079f

Please sign in to comment.