diff --git a/source/build.gradle b/source/build.gradle index 96aa4cce..92b3b66e 100644 --- a/source/build.gradle +++ b/source/build.gradle @@ -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' } diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 47d93baf..39fed06d 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -72,7 +72,8 @@ class VariantProcessor { processResources() processAssets() processJniLibs() - processProguardTxt() + processConsumerProguard() + processGenerateProguard() processDataBinding(bundleTask) processRClasses(transform, bundleTask) } @@ -419,18 +420,6 @@ class VariantProcessor { */ private void processClassesAndJars(TaskProvider bundleTask) { boolean isMinifyEnabled = mVariant.getBuildType().isMinifyEnabled() - if (isMinifyEnabled) { - //merge proguard file - for (archiveLibrary in mAndroidArchiveLibraries) { - List 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") @@ -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) { @@ -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 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() + } + } + } + } }