From a438b2b55c2735b375bcea8d39ae1aa76e8332fc Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Wed, 9 Sep 2020 19:33:51 +0200 Subject: [PATCH 01/20] Improve incremental build --- .../com/kezong/fataar/RProcessor.groovy | 6 ++-- .../com/kezong/fataar/VariantProcessor.groovy | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index 2da936cd..f1022ad3 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -71,8 +71,6 @@ class RProcessor { if (f.exists()) { f.delete() } - mJarDir.getParentFile().deleteDir() - mJarDir.mkdirs() } bundleTask.doLast { @@ -170,7 +168,9 @@ class RProcessor { } private Task createRFileTask(final File destFolder) { - def task = mProject.tasks.create(name: 'createRsFile' + mVariant.name) + def task = mProject.tasks.create(name: 'createRsFile' + mVariant.name) { + outputs.dir(destFolder) + } task.doLast { if (destFolder.exists()) { destFolder.deleteDir() diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 0a21d09f..8dd11c42 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -147,7 +147,6 @@ class VariantProcessor { dependencies = context.queue.getFirst().getDependencies() } } - archiveLibrary.getRootFolder().deleteDir() final def zipFolder = archiveLibrary.getRootFolder() zipFolder.mkdirs() def group = artifact.getModuleVersion().id.group.capitalize() @@ -222,25 +221,30 @@ class VariantProcessor { } private Task handleClassesMergeTask(final boolean isMinifyEnabled) { - final Task task = mProject.tasks.create(name: 'mergeClasses' - + mVariant.name.capitalize()) - task.doFirst { - def dustDir = mVersionAdapter.getClassPathDirFiles().first() - if (isMinifyEnabled) { - ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, dustDir) - ExplodedHelper.processLibsIntoClasses(mProject, mAndroidArchiveLibraries, mJarFiles, dustDir) - } else { - ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, dustDir) + final Task task = mProject.tasks.create(name: 'mergeClasses' + mVariant.name.capitalize()) { + def outputDir = mVersionAdapter.getClassPathDirFiles().first() + outputs.dir(outputDir) + + doFirst { + if (isMinifyEnabled) { + ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, outputDir) + ExplodedHelper.processLibsIntoClasses(mProject, mAndroidArchiveLibraries, mJarFiles, outputDir) + } else { + ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, outputDir) + } } } return task } private Task handleJarMergeTask() { - final Task task = mProject.tasks.create(name: 'mergeJars' - + mVariant.name.capitalize()) - task.doFirst { - ExplodedHelper.processLibsIntoLibs(mProject, mAndroidArchiveLibraries, mJarFiles, mVersionAdapter.getLibsDirFile()) + final Task task = mProject.tasks.create(name: 'mergeJars' + mVariant.name.capitalize()) { + def outputDir = mVersionAdapter.getLibsDirFile() + outputs.dir(outputDir) + + doFirst { + ExplodedHelper.processLibsIntoLibs(mProject, mAndroidArchiveLibraries, mJarFiles, outputDir) + } } return task } From 47ec9a01cc1310c1e834d0e189bfb1e08a0c1b43 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Thu, 17 Sep 2020 18:46:11 +0200 Subject: [PATCH 02/20] Make manifest merging incremental --- .../com/kezong/fataar/VariantProcessor.groovy | 52 +++++++------------ .../com/kezong/fataar/VersionAdapter.groovy | 3 +- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 8a3c9ef9..a0246008 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -1,6 +1,7 @@ package com.kezong.fataar import com.android.build.gradle.api.LibraryVariant +import com.android.build.gradle.tasks.ManifestProcessorTask import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.artifacts.Dependency @@ -206,55 +207,38 @@ class VariantProcessor { * merge manifest */ private void processManifest() { - Task processManifestTask = mVersionAdapter.getProcessManifest() - String manifestInputDir = "${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/manifest" + ManifestProcessorTask processManifestTask = mVersionAdapter.getProcessManifest() + File manifestOutput if (mGradlePluginVersion != null && Utils.compareVersion(mGradlePluginVersion, "3.3.0") >= 0) { manifestOutput = mProject.file("${mProject.buildDir.path}/intermediates/library_manifest/${mVariant.name}/AndroidManifest.xml") } else { - manifestOutput = mProject.file(processManifestTask.getManifestOutputDirectory().absolutePath + '/AndroidManifest.xml') - } - - // AGP 4.0.0 brings in a change which wipes out the output files whenever a task gets rerun - // See https://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/NonIncrementalTask.kt - // The manifest merging task tries to update the manifest in place, by setting input == output, resulting in the input file being explicitly deleted just before the task gets run - // The sleight-of-hand below gets things working again - TaskProvider copyTask = mProject.tasks.register("copy${mVariant.name.capitalize()}Manifest", Copy) { - dependsOn(processManifestTask) - outputs.upToDateWhen { false } - from manifestOutput - into mProject.file(manifestInputDir) + manifestOutput = mProject.file(processManifestTask.getManifestOutputDirectory().absolutePath + "/AndroidManifest.xml") } - List list = new ArrayList<>() - for (archiveLibrary in mAndroidArchiveLibraries) { - list.add(archiveLibrary.getManifest()) - } TaskProvider manifestsMergeTask = mProject.tasks.register("merge${mVariant.name.capitalize()}Manifest", LibraryManifestMerger) { - dependsOn(copyTask) - dependsOn(mExplodeTasks) - + final List inputManifests = new ArrayList<>() + for (archiveLibrary in mAndroidArchiveLibraries) { + def manifest = archiveLibrary.getManifest() + if (manifest.exists()) { + inputManifests.add(archiveLibrary.getManifest()) + } + } setGradleVersion(mProject.getGradle().getGradleVersion()) setGradlePluginVersion(mGradlePluginVersion) setVariantName(mVariant.name) - setMainManifestFile(mProject.file("${manifestInputDir}/AndroidManifest.xml")) - setSecondaryManifestFiles(list) + setMainManifestFile(manifestOutput) + setSecondaryManifestFiles(inputManifests) setOutputFile(manifestOutput) - doFirst { - List existFiles = new ArrayList<>() - getSecondaryManifestFiles().each { - if (it.exists()) { - existFiles.add(it) - } - } - setSecondaryManifestFiles(existFiles) - } } - processManifestTask.finalizedBy(manifestsMergeTask) + processManifestTask.dependsOn(mExplodeTasks) + processManifestTask.doLast { + // Merge manifests + manifestsMergeTask.get().doTaskAction() + } } - private TaskProvider handleClassesMergeTask(final boolean isMinifyEnabled) { final TaskProvider task = mProject.tasks.register('mergeClasses' + mVariant.name.capitalize()) { dependsOn(mExplodeTasks) diff --git a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy index 60868560..5130a6ec 100644 --- a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy @@ -1,6 +1,7 @@ package com.kezong.fataar import com.android.build.gradle.api.LibraryVariant +import com.android.build.gradle.tasks.ManifestProcessorTask import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.file.ConfigurableFileCollection @@ -66,7 +67,7 @@ class VersionAdapter { } } - Task getProcessManifest() { + ManifestProcessorTask getProcessManifest() { if (Utils.compareVersion(mGradlePluginVersion, "3.3.0") >= 0) { return mVariant.getOutputs().first().getProcessManifestProvider().get() } else { From 7e135e0369444a0ec2c12aec5847b3ab9bf72aa8 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Fri, 18 Sep 2020 20:41:22 +0200 Subject: [PATCH 03/20] Make bundle and rebundle tasks compatible with incremental builds --- .../com/kezong/fataar/RProcessor.groovy | 53 +++++++++---------- .../com/kezong/fataar/VersionAdapter.groovy | 8 +-- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index a61319bc..9aa28580 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -1,6 +1,7 @@ package com.kezong.fataar import com.android.build.gradle.api.LibraryVariant +import com.android.build.gradle.tasks.BundleAar import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.tasks.TaskProvider @@ -21,9 +22,9 @@ class RProcessor { private final File mClassDir private final File mJarDir private final File mAarUnZipDir - private final File mAarOutputDir + private final File mIntermediateAarFile + private final File mAarOutputFile private final String mGradlePluginVersion - private String mAarOutputPath private VersionAdapter mVersionAdapter private final Collection mLibraries @@ -41,14 +42,14 @@ class RProcessor { mJarDir = mProject.file("${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}/${mVariant.dirName}/libs") // aar zip file mAarUnZipDir = mJarDir.getParentFile() - // aar output dir - mAarOutputDir = mProject.file("${mProject.getBuildDir()}/outputs/aar/") - - mAarOutputPath = mVersionAdapter.getOutputPath() + // Aar output file + mAarOutputFile = mVersionAdapter.getOutputPath() + // Intermediate aar dir + mIntermediateAarFile = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/aar/${mVariant.dirName}/${mAarOutputFile.name}") } void inject(TaskProvider bundleTask) { - def reBundleAar = createBundleAarTask(mAarUnZipDir, mAarOutputDir, mAarOutputPath) + def reBundleAar = createBundleAarTask(mAarUnZipDir, mAarOutputFile.parentFile, mAarOutputFile.name) def RJarTask = createRJarTask(mClassDir, mJarDir, reBundleAar) def RClassTask = createRClassTask(mJavaDir, mClassDir, RJarTask) def RFileTask = createRFileTask(mJavaDir, RClassTask) @@ -56,38 +57,32 @@ class RProcessor { reBundleAar.configure { doFirst { mProject.copy { - from mProject.zipTree(mAarOutputPath) + from mProject.zipTree(mIntermediateAarFile) into mAarUnZipDir } deleteEmptyDir(mAarUnZipDir) } doLast { - Utils.logAnytime("target: $mAarOutputPath") + Utils.logAnytime("target: ${mAarOutputFile.absolutePath}") } } - bundleTask.configure { + bundleTask.configure { BundleAar it -> finalizedBy(RFileTask) - doFirst { - File f = new File(mAarOutputPath) - if (f.exists()) { - f.delete() - } - mJarDir.mkdirs() + // Redirect bundle output to intermediate directory to avoid breaking incremental builds + // because of bundle and reBundle tasks having the same output + if (Utils.compareVersion(mProject.gradle.gradleVersion, "6.0.1") >= 0) { + it.getDestinationDirectory().set(mIntermediateAarFile.parentFile) + } else { + it.destinationDir = mIntermediateAarFile.parentFile } - doLast { - // support gradle 5.1 && gradle plugin 3.4 before, the outputName is changed - File file = new File(mAarOutputPath) - if (!file.exists()) { - mAarOutputPath = mAarOutputDir.absolutePath + "/" + mProject.name + ".aar" - if (Utils.compareVersion(mProject.gradle.gradleVersion, "6.0.1") >= 0) { - reBundleAar.getArchiveFileName().set(new File(mAarOutputPath).name) - } else { - reBundleAar.archiveName = new File(mAarOutputPath).name - } + doFirst { + if (mIntermediateAarFile.exists()) { + mIntermediateAarFile.delete() } + mJarDir.mkdirs() } } } @@ -239,16 +234,16 @@ class RProcessor { return task } - private TaskProvider createBundleAarTask(final File from, final File destDir, final String filePath) { + private TaskProvider createBundleAarTask(final File from, final File destDir, final String aarFileName) { String taskName = "reBundleAar${mVariant.name.capitalize()}" TaskProvider task = mProject.getTasks().register(taskName, Zip.class) { it.from from it.include "**" if (Utils.compareVersion(mProject.gradle.gradleVersion, "6.0.1") >= 0) { - it.getArchiveFileName().set(new File(filePath).name) + it.getArchiveFileName().set(aarFileName) it.getDestinationDirectory().set(destDir) } else { - it.archiveName = new File(filePath).name + it.archiveName = aarFileName it.destinationDir = destDir } } diff --git a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy index 5130a6ec..4270b87e 100644 --- a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy @@ -106,16 +106,16 @@ class VersionAdapter { } } - String getOutputPath() { + File getOutputPath() { if (Utils.compareVersion(mGradlePluginVersion, "3.3.0") >= 0) { String fileName = mVariant.outputs.first().outputFileName if (Utils.compareVersion(mProject.gradle.gradleVersion, "6.0.1") >= 0) { - return new File(mVariant.getPackageLibraryProvider().get().getDestinationDirectory().getAsFile().get(), fileName).absolutePath + return new File(mVariant.getPackageLibraryProvider().get().getDestinationDirectory().getAsFile().get(), fileName) } else { - return new File(mVariant.getPackageLibraryProvider().get().getDestinationDir(), fileName).absolutePath + return new File(mVariant.getPackageLibraryProvider().get().getDestinationDir(), fileName) } } else { - return mVariant.outputs.first().outputFile.absolutePath + return mVariant.outputs.first().outputFile } } } From 948a967f846530a60f2ab62f2daa1d12d867a493 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Sat, 19 Sep 2020 20:32:18 +0200 Subject: [PATCH 04/20] Fix incorrect directory for jar libs --- source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy index 4270b87e..bd0eab08 100644 --- a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy @@ -51,7 +51,7 @@ class VersionAdapter { File getLibsDirFile() { if (Utils.compareVersion(mGradlePluginVersion, '3.6.0') >= 0) { - return mProject.file("${mProject.buildDir.path}/intermediates/aar_libs_directory/${mVariant.dirName}/libs") + return mProject.file("${mProject.buildDir.path}/intermediates/aar_libs_directory/${mVariant.name}/libs") } else if (Utils.compareVersion(mGradlePluginVersion, '3.1.0') >= 0) { return mProject.file(mProject.buildDir.path + '/intermediates/packaged-classes/' + mVariant.dirName + "/libs") } else { From 34019319786dd5b7e969e6fdbb18a85426263e00 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Sat, 19 Sep 2020 20:36:17 +0200 Subject: [PATCH 05/20] Move aar unzipping to bundle task --- .../groovy/com/kezong/fataar/RProcessor.groovy | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index 9aa28580..112c749a 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -55,13 +55,6 @@ class RProcessor { def RFileTask = createRFileTask(mJavaDir, RClassTask) reBundleAar.configure { - doFirst { - mProject.copy { - from mProject.zipTree(mIntermediateAarFile) - into mAarUnZipDir - } - deleteEmptyDir(mAarUnZipDir) - } doLast { Utils.logAnytime("target: ${mAarOutputFile.absolutePath}") } @@ -84,6 +77,14 @@ class RProcessor { } mJarDir.mkdirs() } + + doLast { + mProject.copy { + from mProject.zipTree(mIntermediateAarFile) + into mAarUnZipDir + } + deleteEmptyDir(mAarUnZipDir) + } } } From 6f7812311c99777c2a3787b586a013cbbb6de2d2 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Sat, 19 Sep 2020 21:57:57 +0200 Subject: [PATCH 06/20] Add inputs to mergeClasses and mergeJars tasks --- .../com/kezong/fataar/VariantProcessor.groovy | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index a0246008..5c9bfceb 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -96,7 +96,6 @@ class VariantProcessor { } TaskProvider bundleTask = FlavorArtifact.getBundleTaskProvider(mProject, mVariant) - processCache() processArtifacts(prepareTask, bundleTask) processClassesAndJars(bundleTask) if (mAndroidArchiveLibraries.isEmpty()) { @@ -144,18 +143,6 @@ class VariantProcessor { } } - private void processCache() { - if (Utils.compareVersion(mGradlePluginVersion, "3.5.0") >= 0) { - mVersionAdapter.getLibsDirFile().deleteDir() - mVersionAdapter.getClassPathDirFiles().first().deleteDir() - } - - File reBundleFile = mProject.file("${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}/${mVariant.dirName}") - if (reBundleFile != null && reBundleFile.exists()) { - reBundleFile.delete() - } - } - /** * exploded artifact files */ @@ -240,9 +227,15 @@ class VariantProcessor { } private TaskProvider handleClassesMergeTask(final boolean isMinifyEnabled) { - final TaskProvider task = mProject.tasks.register('mergeClasses' + mVariant.name.capitalize()) { + final TaskProvider task = mProject.tasks.register("mergeClasses" + mVariant.name.capitalize()) { dependsOn(mExplodeTasks) dependsOn(mVersionAdapter.getJavaCompileTask()) + + inputs.files(mAndroidArchiveLibraries.stream().map { it.classesJarFile }.collect()) + if (isMinifyEnabled) { + inputs.files(mAndroidArchiveLibraries.stream().map { it.localJars }.collect()) + inputs.files(mJarFiles) + } def outputDir = mVersionAdapter.getClassPathDirFiles().first() outputs.dir(outputDir) @@ -259,12 +252,16 @@ class VariantProcessor { } private TaskProvider handleJarMergeTask(final TaskProvider syncLibTask) { - final TaskProvider task = mProject.tasks.register('mergeJars' + mVariant.name.capitalize()) { + final TaskProvider task = mProject.tasks.register("mergeJars" + mVariant.name.capitalize()) { dependsOn(mExplodeTasks) dependsOn(mVersionAdapter.getJavaCompileTask()) mustRunAfter(syncLibTask) + + inputs.files(mAndroidArchiveLibraries.stream().map { it.localJars }.collect()) + inputs.files(mJarFiles) def outputDir = mVersionAdapter.getLibsDirFile() outputs.dir(outputDir) + doFirst { ExplodedHelper.processLibsIntoLibs(mProject, mAndroidArchiveLibraries, mJarFiles, outputDir) } From 5e3bbc83c9c9781aca6c85d80c45a168c57ee78d Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:03:22 +0200 Subject: [PATCH 07/20] Improve ExplodedHelper logic --- .../com/kezong/fataar/ExplodedHelper.groovy | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/ExplodedHelper.groovy b/source/src/main/groovy/com/kezong/fataar/ExplodedHelper.groovy index 12b31b8c..d0471aad 100644 --- a/source/src/main/groovy/com/kezong/fataar/ExplodedHelper.groovy +++ b/source/src/main/groovy/com/kezong/fataar/ExplodedHelper.groovy @@ -10,7 +10,8 @@ import org.gradle.api.Project class ExplodedHelper { static void processLibsIntoLibs(Project project, - Collection androidLibraries, Collection jarFiles, + Collection androidLibraries, + Collection jarFiles, File folderOut) { for (androidLibrary in androidLibraries) { if (!androidLibrary.rootFolder.exists()) { @@ -18,27 +19,24 @@ class ExplodedHelper { continue } if (androidLibrary.localJars.isEmpty()) { - Utils.logInfo("Not found jar file, Library:${androidLibrary.name}") + Utils.logInfo("Not found jar file, Library: ${androidLibrary.name}") } else { - Utils.logInfo("Merge ${androidLibrary.name} jar file, Library:${androidLibrary.name}") - } - androidLibrary.localJars.each { - Utils.logInfo(it.path) - } - project.copy { - from(androidLibrary.localJars) - into folderOut + Utils.logInfo("Merge ${androidLibrary.name} local jar files") + project.copy { + from(androidLibrary.localJars) + into(folderOut) + } } } for (jarFile in jarFiles) { - if (!jarFile.exists()) { + if (jarFile.exists()) { + Utils.logInfo("Copy jar from: $jarFile to $folderOut.absolutePath") + project.copy { + from(jarFile) + into(folderOut) + } + } else { Utils.logInfo('[warning]' + jarFile + ' not found!') - continue - } - Utils.logInfo('copy jar from: ' + jarFile + " to " + folderOut.absolutePath) - project.copy { - from(jarFile) - into folderOut } } } @@ -65,8 +63,9 @@ class ExplodedHelper { } static void processLibsIntoClasses(Project project, - Collection androidLibraries, Collection jarFiles, - File folderOut) { + Collection androidLibraries, + Collection jarFiles, + File folderOut) { Utils.logInfo('Merge Libs') Collection allJarFiles = new ArrayList<>() for (androidLibrary in androidLibraries) { @@ -78,10 +77,9 @@ class ExplodedHelper { allJarFiles.addAll(androidLibrary.localJars) } for (jarFile in jarFiles) { - if (!jarFile.exists()) { - continue + if (jarFile.exists()) { + allJarFiles.add(jarFile) } - allJarFiles.add(jarFile) } for (jarFile in allJarFiles) { project.copy { From 5d38f233f6cb7fc94ac9125fe21feb677a3d9800 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 13:56:56 +0200 Subject: [PATCH 08/20] Improve generateResources task logic to avoid unnecessary iterations --- .../com/kezong/fataar/VariantProcessor.groovy | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 5c9bfceb..e1285f55 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -1,6 +1,7 @@ package com.kezong.fataar import com.android.build.gradle.api.LibraryVariant +import com.android.build.gradle.internal.api.DefaultAndroidSourceSet import com.android.build.gradle.tasks.ManifestProcessorTask import org.gradle.api.Project import org.gradle.api.Task @@ -9,6 +10,7 @@ import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.artifacts.ResolvedDependency import org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskDependency import org.gradle.api.tasks.TaskProvider @@ -307,7 +309,7 @@ class VariantProcessor { } /** - * merge R.txt(actually is to fix issue caused by provided configuration) and res + * merge R.txt (actually is to fix issue caused by provided configuration) and res * * Here I have to inject res into "main" instead of "variant.name". * To avoid the res from embed dependencies being used, once they have the same res Id with main res. @@ -316,21 +318,23 @@ class VariantProcessor { * Adding "android.disableResourceValidation=true" to "gradle.properties" can do a trick to skip the exception, but is not recommended. */ private void processResourcesAndR() { - String taskPath = 'generate' + mVariant.name.capitalize() + 'Resources' + String taskPath = "generate" + mVariant.name.capitalize() + "Resources" TaskProvider resourceGenTask = mProject.tasks.named(taskPath) if (resourceGenTask == null) { throw new RuntimeException("Can not find task ${taskPath}!") } - + resourceGenTask.configure { dependsOn(mExplodeTasks) + inputs.files(mAndroidArchiveLibraries.stream().map { it.resFolder }.collect()) + .withPathSensitivity(PathSensitivity.RELATIVE) doFirst { - for (archiveLibrary in mAndroidArchiveLibraries) { - mProject.android.sourceSets.each { - if (it.name == mVariant.name) { - Utils.logInfo("Merge resource,Library res:${archiveLibrary.resFolder}") - it.res.srcDir(archiveLibrary.resFolder) + mProject.android.sourceSets.each { DefaultAndroidSourceSet sourceSet -> + if (sourceSet.name == mVariant.name) { + for (archiveLibrary in mAndroidArchiveLibraries) { + Utils.logAnytime("Merge resource,Library res:${archiveLibrary.resFolder} into: ${sourceSet.res.srcDirs}") + sourceSet.res.srcDir(archiveLibrary.resFolder) } } } From 35d48908f83691158e3afc648b1531b421b25ac8 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 13:57:22 +0200 Subject: [PATCH 09/20] Add path sensitivity to all inputs --- source/src/main/groovy/com/kezong/fataar/RProcessor.groovy | 6 +++++- .../main/groovy/com/kezong/fataar/VariantProcessor.groovy | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index 112c749a..cf4f9591 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -4,6 +4,7 @@ import com.android.build.gradle.api.LibraryVariant import com.android.build.gradle.tasks.BundleAar import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.bundling.Zip import org.gradle.api.tasks.compile.JavaCompile @@ -164,8 +165,11 @@ class RProcessor { } private TaskProvider createRFileTask(final File destFolder, final TaskProvider RClassTask) { - def task = mProject.tasks.register('createRsFile' + mVariant.name) { + def task = mProject.tasks.register("createRsFile${mVariant.name}") { finalizedBy(RClassTask) + + inputs.files(mLibraries.stream().map { it.symbolFile }.collect()) + .withPathSensitivity(PathSensitivity.RELATIVE) outputs.dir(destFolder) doLast { diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index e1285f55..0a3d1c36 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -234,9 +234,11 @@ class VariantProcessor { dependsOn(mVersionAdapter.getJavaCompileTask()) inputs.files(mAndroidArchiveLibraries.stream().map { it.classesJarFile }.collect()) + .withPathSensitivity(PathSensitivity.RELATIVE) if (isMinifyEnabled) { inputs.files(mAndroidArchiveLibraries.stream().map { it.localJars }.collect()) - inputs.files(mJarFiles) + .withPathSensitivity(PathSensitivity.RELATIVE) + inputs.files(mJarFiles).withPathSensitivity(PathSensitivity.RELATIVE) } def outputDir = mVersionAdapter.getClassPathDirFiles().first() outputs.dir(outputDir) @@ -260,7 +262,8 @@ class VariantProcessor { mustRunAfter(syncLibTask) inputs.files(mAndroidArchiveLibraries.stream().map { it.localJars }.collect()) - inputs.files(mJarFiles) + .withPathSensitivity(PathSensitivity.RELATIVE) + inputs.files(mJarFiles).withPathSensitivity(PathSensitivity.RELATIVE) def outputDir = mVersionAdapter.getLibsDirFile() outputs.dir(outputDir) From 348cc0fb4f7e8bf3bd8816004eb42638da13a3b9 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 16:20:08 +0200 Subject: [PATCH 10/20] Add res to generateResources task during configuration --- .../com/kezong/fataar/VariantProcessor.groovy | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 0a3d1c36..85a53950 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -326,19 +326,15 @@ class VariantProcessor { if (resourceGenTask == null) { throw new RuntimeException("Can not find task ${taskPath}!") } - + resourceGenTask.configure { dependsOn(mExplodeTasks) - inputs.files(mAndroidArchiveLibraries.stream().map { it.resFolder }.collect()) - .withPathSensitivity(PathSensitivity.RELATIVE) - doFirst { - mProject.android.sourceSets.each { DefaultAndroidSourceSet sourceSet -> - if (sourceSet.name == mVariant.name) { - for (archiveLibrary in mAndroidArchiveLibraries) { - Utils.logAnytime("Merge resource,Library res:${archiveLibrary.resFolder} into: ${sourceSet.res.srcDirs}") - sourceSet.res.srcDir(archiveLibrary.resFolder) - } + mProject.android.sourceSets.each { DefaultAndroidSourceSet sourceSet -> + if (sourceSet.name == mVariant.name) { + for (archiveLibrary in mAndroidArchiveLibraries) { + Utils.logInfo("Merge resource,Library res:${archiveLibrary.resFolder}") + sourceSet.res.srcDir(archiveLibrary.resFolder) } } } From 42e6d41618773e3d8295b5fe77edf6d6f62af38c Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 16:58:41 +0200 Subject: [PATCH 11/20] Improve loops logic for mergeAssets task --- .../com/kezong/fataar/VariantProcessor.groovy | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 85a53950..b8fc8fff 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -352,21 +352,19 @@ class VariantProcessor { throw new RuntimeException("Can not find task in variant.getMergeAssets()!") } + assetsTask.dependsOn(mExplodeTasks) assetsTask.doFirst { - for (archiveLibrary in mAndroidArchiveLibraries) { - if (archiveLibrary.assetsFolder != null && archiveLibrary.assetsFolder.exists()) { - mProject.android.sourceSets.each { - if (it.name == mVariant.name) { + mProject.android.sourceSets.each { + if (it.name == mVariant.name) { + for (archiveLibrary in mAndroidArchiveLibraries) { + if (archiveLibrary.assetsFolder != null && archiveLibrary.assetsFolder.exists()) { + Utils.logInfo("Merge assets,Library assets folder:${archiveLibrary.assetsFolder}") it.assets.srcDir(archiveLibrary.assetsFolder) } } } } } - - mExplodeTasks.each { it -> - assetsTask.dependsOn it - } } /** From 74a55fa2ff26b1ea3a321438edb5880c798c07bf Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 18:01:37 +0200 Subject: [PATCH 12/20] Fix ordering issues --- .../groovy/com/kezong/fataar/VariantProcessor.groovy | 12 ++++++------ .../com/kezong/fataar/AndroidArchiveLibrary.java | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index b8fc8fff..7a985f33 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -261,7 +261,7 @@ class VariantProcessor { dependsOn(mVersionAdapter.getJavaCompileTask()) mustRunAfter(syncLibTask) - inputs.files(mAndroidArchiveLibraries.stream().map { it.localJars }.collect()) + inputs.files(mAndroidArchiveLibraries.stream().map { it.libsFolder }.collect()) .withPathSensitivity(PathSensitivity.RELATIVE) inputs.files(mJarFiles).withPathSensitivity(PathSensitivity.RELATIVE) def outputDir = mVersionAdapter.getLibsDirFile() @@ -292,16 +292,16 @@ class VariantProcessor { } } - String taskPath = mVersionAdapter.getSyncLibJarsTaskPath() - TaskProvider syncLibTask = mProject.tasks.named(taskPath) - if (syncLibTask == null) { - throw new RuntimeException("Can not find task ${taskPath}!") - } + TaskProvider syncLibTask = mProject.tasks.named(mVersionAdapter.getSyncLibJarsTaskPath()) + TaskProvider extractAnnotationsTask = mProject.tasks.named("extract${mVariant.name.capitalize()}Annotations") TaskProvider mergeClasses = handleClassesMergeTask(isMinifyEnabled) syncLibTask.configure { dependsOn(mergeClasses) } + extractAnnotationsTask.configure { + mustRunAfter(mergeClasses) + } if (!isMinifyEnabled) { TaskProvider mergeJars = handleJarMergeTask(syncLibTask) diff --git a/source/src/main/java/com/kezong/fataar/AndroidArchiveLibrary.java b/source/src/main/java/com/kezong/fataar/AndroidArchiveLibrary.java index dcdc286b..e54ab18f 100644 --- a/source/src/main/java/com/kezong/fataar/AndroidArchiveLibrary.java +++ b/source/src/main/java/com/kezong/fataar/AndroidArchiveLibrary.java @@ -65,13 +65,17 @@ public File getAssetsFolder() { return new File(getRootFolder(), "assets"); } + public File getLibsFolder() { + return new File(getRootFolder(), "libs"); + } + public File getClassesJarFile() { return new File(getRootFolder(), "classes.jar"); } public Collection getLocalJars() { List localJars = new ArrayList<>(); - File[] jarList = new File(getRootFolder(), "libs").listFiles(); + File[] jarList = getLibsFolder().listFiles(); if (jarList != null) { for (File jars : jarList) { if (jars.isFile() && jars.getName().endsWith(".jar")) { From fd57eebc7f59229603f0f5677d334f4e87444979 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 19:26:08 +0200 Subject: [PATCH 13/20] Re process manifest when a secondary manifest is modified --- .../com/kezong/fataar/VariantProcessor.groovy | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 7a985f33..7a45dae6 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -205,14 +205,12 @@ class VariantProcessor { manifestOutput = mProject.file(processManifestTask.getManifestOutputDirectory().absolutePath + "/AndroidManifest.xml") } + final List inputManifests = new ArrayList<>() + for (archiveLibrary in mAndroidArchiveLibraries) { + inputManifests.add(archiveLibrary.getManifest()) + } + TaskProvider manifestsMergeTask = mProject.tasks.register("merge${mVariant.name.capitalize()}Manifest", LibraryManifestMerger) { - final List inputManifests = new ArrayList<>() - for (archiveLibrary in mAndroidArchiveLibraries) { - def manifest = archiveLibrary.getManifest() - if (manifest.exists()) { - inputManifests.add(archiveLibrary.getManifest()) - } - } setGradleVersion(mProject.getGradle().getGradleVersion()) setGradlePluginVersion(mGradlePluginVersion) setVariantName(mVariant.name) @@ -222,6 +220,7 @@ class VariantProcessor { } processManifestTask.dependsOn(mExplodeTasks) + processManifestTask.inputs.files(inputManifests) processManifestTask.doLast { // Merge manifests manifestsMergeTask.get().doTaskAction() From d079692d45a41cdf10f0d43aac23482eee5ea208 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Mon, 21 Sep 2020 19:38:10 +0200 Subject: [PATCH 14/20] Bump publish version --- source/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/build.gradle b/source/build.gradle index 31334f10..a0aee076 100644 --- a/source/build.gradle +++ b/source/build.gradle @@ -37,7 +37,7 @@ publish { userOrg = 'kezong' groupId = 'com.kezong' artifactId = 'fat-aar' - publishVersion = '1.2.16' + publishVersion = '1.2.17' desc = 'Gradle plugin for merging dependencies applies to gradle plugin version 3.+' website = 'https://github.com/kezong/fat-aar-android' } From e32821d81c87f5744d669867bdc24bdf98b7d8e8 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Tue, 22 Sep 2020 16:39:43 +0200 Subject: [PATCH 15/20] Fix removed resources appearing in output aar --- example/lib-aar/libs/{lib1.jar => lib3.jar} | Bin example/lib-aar/src/main/res/layout/test_layout.xml | 10 ---------- .../main/groovy/com/kezong/fataar/RProcessor.groovy | 2 ++ .../com/kezong/fataar/VariantProcessor.groovy | 5 +++++ 4 files changed, 7 insertions(+), 10 deletions(-) rename example/lib-aar/libs/{lib1.jar => lib3.jar} (100%) delete mode 100644 example/lib-aar/src/main/res/layout/test_layout.xml diff --git a/example/lib-aar/libs/lib1.jar b/example/lib-aar/libs/lib3.jar similarity index 100% rename from example/lib-aar/libs/lib1.jar rename to example/lib-aar/libs/lib3.jar diff --git a/example/lib-aar/src/main/res/layout/test_layout.xml b/example/lib-aar/src/main/res/layout/test_layout.xml deleted file mode 100644 index 8c1f1488..00000000 --- a/example/lib-aar/src/main/res/layout/test_layout.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - \ No newline at end of file diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index cf4f9591..d631cf74 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -76,6 +76,8 @@ class RProcessor { if (mIntermediateAarFile.exists()) { mIntermediateAarFile.delete() } + // Delete previously unzipped data. + mAarUnZipDir.deleteDir() mJarDir.mkdirs() } diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 7a45dae6..8132dacc 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -175,6 +175,11 @@ class VariantProcessor { Task explodeTask = mProject.tasks.create(taskName, Copy) { from mProject.zipTree(artifact.file.absolutePath) into zipFolder + + doFirst { + // Delete previously extracted data + zipFolder.deleteDir() + } } if (dependencies.size() == 0) { From d047830e34fac6983f617a34818b25d1a0284008 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Tue, 22 Sep 2020 16:43:34 +0200 Subject: [PATCH 16/20] Revert unwanted changes --- example/lib-aar/libs/lib3.jar | Bin 1050 -> 0 bytes .../lib-aar/src/main/res/layout/test_layout.xml | 10 ++++++++++ 2 files changed, 10 insertions(+) delete mode 100644 example/lib-aar/libs/lib3.jar create mode 100644 example/lib-aar/src/main/res/layout/test_layout.xml diff --git a/example/lib-aar/libs/lib3.jar b/example/lib-aar/libs/lib3.jar deleted file mode 100644 index a90d7e9a79c855ed41d5fdfe545af7b7bb929875..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1050 zcmWIWW@h1HVBp|jSY0&JmjMWvKm-tQ0UF7xF)jD_P{N^BoE5;9=K6=W8W*AUE+*TGK zJ2^iW!$M>=+)y>ysa5%T>3Ee2pejvC&CN$qkM3y+Eb6lo%Mx=klQ8r}Z_R^F$ugo(>9&`ZEqg)2psHSm}9 zZ zMcF=O7VYRPr)jgp*7NsXx*N7?*3`*UbKdCuaWHrwCDH-(>7CQ5%?5})&1!Ru~B z;K}qzY1MZ-p1J9+<2bq3wxo5RXQe8z1gqbvU0ME?#+#XQ}wFmBprCa zL&0y~VF^RwdCU)wO23#on=$FwiEhC@iOcfLZXSPr-PnC8Kfs%jNrV}9N& + + + + \ No newline at end of file From 6637422efde70092b98597d4afd560351b2bb758 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Tue, 22 Sep 2020 16:47:04 +0200 Subject: [PATCH 17/20] Revert unwanted jar deletion --- example/lib-aar/libs/lib1.jar | Bin 0 -> 1050 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 example/lib-aar/libs/lib1.jar diff --git a/example/lib-aar/libs/lib1.jar b/example/lib-aar/libs/lib1.jar new file mode 100644 index 0000000000000000000000000000000000000000..a90d7e9a79c855ed41d5fdfe545af7b7bb929875 GIT binary patch literal 1050 zcmWIWW@h1HVBp|jSY0&JmjMWvKm-tQ0UF7xF)jD_P{N^BoE5;9=K6=W8W*AUE+*TGK zJ2^iW!$M>=+)y>ysa5%T>3Ee2pejvC&CN$qkM3y+Eb6lo%Mx=klQ8r}Z_R^F$ugo(>9&`ZEqg)2psHSm}9 zZ zMcF=O7VYRPr)jgp*7NsXx*N7?*3`*UbKdCuaWHrwCDH-(>7CQ5%?5})&1!Ru~B z;K}qzY1MZ-p1J9+<2bq3wxo5RXQe8z1gqbvU0ME?#+#XQ}wFmBprCa zL&0y~VF^RwdCU)wO23#on=$FwiEhC@iOcfLZXSPr-PnC8Kfs%jNrV}9N& Date: Tue, 22 Sep 2020 18:01:35 +0200 Subject: [PATCH 18/20] Fix removed libs appearing in output aar --- .../groovy/com/kezong/fataar/Constants.groovy | 2 +- .../groovy/com/kezong/fataar/RProcessor.groovy | 18 +++++++++--------- .../com/kezong/fataar/VariantProcessor.groovy | 3 +++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/Constants.groovy b/source/src/main/groovy/com/kezong/fataar/Constants.groovy index 76ae3318..9f5a994c 100644 --- a/source/src/main/groovy/com/kezong/fataar/Constants.groovy +++ b/source/src/main/groovy/com/kezong/fataar/Constants.groovy @@ -4,5 +4,5 @@ class Constants { public static final String RE_BUNDLE_FOLDER = "aar_rebundle" - public static final String INTERMEDIATES_TEMP_FOLDER = "fat-r" + public static final String INTERMEDIATES_TEMP_FOLDER = "fat-aar" } \ No newline at end of file diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index d631cf74..30160e2d 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -35,18 +35,18 @@ class RProcessor { mLibraries = libraries mGradlePluginVersion = version mVersionAdapter = new VersionAdapter(project, variant, version) - // R.java dir - mJavaDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r/${mVariant.dirName}") - // R.class compile dir - mClassDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r-class/${mVariant.dirName}") - // R.jar dir - mJarDir = mProject.file("${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}/${mVariant.dirName}/libs") - // aar zip file - mAarUnZipDir = mJarDir.getParentFile() // Aar output file mAarOutputFile = mVersionAdapter.getOutputPath() + // R.java dir + mJavaDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r/${mVariant.name}") + // R.class compile dir + mClassDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r-class/${mVariant.name}") // Intermediate aar dir - mIntermediateAarFile = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/aar/${mVariant.dirName}/${mAarOutputFile.name}") + mIntermediateAarFile = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/aar/${mVariant.name}/${mAarOutputFile.name}") + // R.jar dir + mJarDir = mProject.file("${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}/${mVariant.name}/libs") + // Aar unzip dir + mAarUnZipDir = mJarDir.parentFile } void inject(TaskProvider bundleTask) { diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 8132dacc..05fb22e5 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -302,6 +302,9 @@ class VariantProcessor { TaskProvider mergeClasses = handleClassesMergeTask(isMinifyEnabled) syncLibTask.configure { dependsOn(mergeClasses) + inputs.files(mAndroidArchiveLibraries.stream().map { it.libsFolder }.collect()) + .withPathSensitivity(PathSensitivity.RELATIVE) + inputs.files(mJarFiles).withPathSensitivity(PathSensitivity.RELATIVE) } extractAnnotationsTask.configure { mustRunAfter(mergeClasses) From 06c8f5c89ca3e56d7e5bae27b7a461934852e845 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Thu, 24 Sep 2020 17:40:59 +0200 Subject: [PATCH 19/20] Fix removed classes appearing in output aar --- .../com/kezong/fataar/VariantProcessor.groovy | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 05fb22e5..dd265338 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -2,6 +2,7 @@ package com.kezong.fataar import com.android.build.gradle.api.LibraryVariant import com.android.build.gradle.internal.api.DefaultAndroidSourceSet +import com.android.build.gradle.internal.tasks.LibraryAarJarsTask import com.android.build.gradle.tasks.ManifestProcessorTask import org.gradle.api.Project import org.gradle.api.Task @@ -14,6 +15,10 @@ import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskDependency import org.gradle.api.tasks.TaskProvider +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + /** * Processor for variant * Created by Vigi on 2017/2/24. @@ -177,7 +182,7 @@ class VariantProcessor { into zipFolder doFirst { - // Delete previously extracted data + // Delete previously extracted data. zipFolder.deleteDir() } } @@ -244,15 +249,32 @@ class VariantProcessor { .withPathSensitivity(PathSensitivity.RELATIVE) inputs.files(mJarFiles).withPathSensitivity(PathSensitivity.RELATIVE) } - def outputDir = mVersionAdapter.getClassPathDirFiles().first() + File outputDir = mProject.file("${mProject.buildDir}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/merge_classes/${mVariant.name}") + File javacDir = mVersionAdapter.getClassPathDirFiles().first() outputs.dir(outputDir) doFirst { + // Delete previous output. + def pathsToDelete = new ArrayList() + mProject.fileTree(outputDir).forEach { + pathsToDelete.add(Paths.get(outputDir.absolutePath).relativize(Paths.get(it.absolutePath))) + } + outputDir.deleteDir() + // Delete output files from javac dir. + pathsToDelete.forEach { + Files.deleteIfExists(Paths.get("$javacDir.absolutePath/${it.toString()}")) + } + } + + doLast { + ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, outputDir) if (isMinifyEnabled) { - ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, outputDir) ExplodedHelper.processLibsIntoClasses(mProject, mAndroidArchiveLibraries, mJarFiles, outputDir) - } else { - ExplodedHelper.processClassesJarInfoClasses(mProject, mAndroidArchiveLibraries, outputDir) + } + + mProject.copy { + from outputDir + into javacDir } } } From 33419d82d438a549773953b911ac5be57f38d2f8 Mon Sep 17 00:00:00 2001 From: puboe <8038503+puboe@users.noreply.github.com> Date: Thu, 24 Sep 2020 18:51:03 +0200 Subject: [PATCH 20/20] Rename method --- source/src/main/groovy/com/kezong/fataar/RProcessor.groovy | 2 +- .../src/main/groovy/com/kezong/fataar/VariantProcessor.groovy | 2 +- source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index 30160e2d..78ab1918 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -36,7 +36,7 @@ class RProcessor { mGradlePluginVersion = version mVersionAdapter = new VersionAdapter(project, variant, version) // Aar output file - mAarOutputFile = mVersionAdapter.getOutputPath() + mAarOutputFile = mVersionAdapter.getOutputFile() // R.java dir mJavaDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r/${mVariant.name}") // R.class compile dir diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index dd265338..8faae9a8 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -254,7 +254,7 @@ class VariantProcessor { outputs.dir(outputDir) doFirst { - // Delete previous output. + // Extract relative paths and delete previous output. def pathsToDelete = new ArrayList() mProject.fileTree(outputDir).forEach { pathsToDelete.add(Paths.get(outputDir.absolutePath).relativize(Paths.get(it.absolutePath))) diff --git a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy index bd0eab08..26204606 100644 --- a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy @@ -106,7 +106,7 @@ class VersionAdapter { } } - File getOutputPath() { + File getOutputFile() { if (Utils.compareVersion(mGradlePluginVersion, "3.3.0") >= 0) { String fileName = mVariant.outputs.first().outputFileName if (Utils.compareVersion(mProject.gradle.gradleVersion, "6.0.1") >= 0) {