From 91d9c1b02fe522754fe08f0542349e7784cf1290 Mon Sep 17 00:00:00 2001 From: kezong <379977@qq.com> Date: Tue, 4 Jun 2019 10:55:08 +0800 Subject: [PATCH] fix R file missing when upload maven --- example/build.gradle | 2 +- .../com/kezong/fataar/VariantProcessor.groovy | 41 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/example/build.gradle b/example/build.gradle index 2e56244a..5c371eb6 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.4.1' - classpath 'com.kezong:fat-aar:1.1.6' + classpath 'com.kezong:fat-aar:1.1.7' } } diff --git a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy index 058ab2a9..2db27513 100644 --- a/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy @@ -386,21 +386,10 @@ class VariantProcessor { aarOutputFilePath = output.outputFile.absolutePath } - if (bundleTask != null) { - bundleTask.doFirst { - File f = new File(aarOutputFilePath) - if (f.exists()) { - f.delete() - } - libFolder.getParentFile().deleteDir() - libFolder.mkdirs() - } - } - def RFileTask = createRFileTask(rFolder) def RClassTask = createRClassTask(rFolder, rClassFolder) def RJarTask = createRJarTask(rClassFolder, libFolder) - def bundleAar = createBundleAarTask(outputDir, aarDir, aarOutputFilePath) + def reBundleAar = createBundleAarTask(outputDir, aarDir, aarOutputFilePath) if (mGradlePluginVersion != null && Utils.compareVersion(mGradlePluginVersion, "3.3.0") >= 0) { RClassTask.doFirst { mProject.copy { @@ -410,31 +399,39 @@ class VariantProcessor { } } - bundleAar.doFirst { - Utils.logInfo("Assemble final aar, from:$outputDir.absolutePath") + reBundleAar.doFirst { + Utils.logInfo("reBundle final aar, from:$outputDir.absolutePath") mProject.copy { from mProject.zipTree(aarOutputFilePath) into outputDir } deleteEmptyDir(outputDir) } - bundleAar.doLast { - Utils.logInfo("Assemble final aar, target:$aarOutputFilePath") + reBundleAar.doLast { + Utils.logInfo("reBundle final aar, target:$aarOutputFilePath") + } + + bundleTask.doFirst { + File f = new File(aarOutputFilePath) + if (f.exists()) { + f.delete() + } + libFolder.getParentFile().deleteDir() + libFolder.mkdirs() } - Task assembleTask = mProject.tasks.findByPath("assemble${mVariant.name.capitalize()}") - assembleTask.doLast { + bundleTask.doLast { // support gradle 5.1 && gradle plugin 3.4 before, the outputName is changed File file = new File(aarOutputFilePath) if (!file.exists()) { aarOutputFilePath = aarDir.absolutePath + "/" + mProject.name + ".aar" - bundleAar.archiveName = new File(aarOutputFilePath).name + reBundleAar.archiveName = new File(aarOutputFilePath).name } } - assembleTask.finalizedBy(RFileTask) + bundleTask.finalizedBy(RFileTask) RFileTask.finalizedBy(RClassTask) RClassTask.finalizedBy(RJarTask) - RJarTask.finalizedBy(bundleAar) + RJarTask.finalizedBy(reBundleAar) } private def createRFile(AndroidArchiveLibrary library, def rFolder) { @@ -515,7 +512,7 @@ class VariantProcessor { } private Task createBundleAarTask(File from, File destDir, String filePath) { - String taskName = "assembleFinalAar${mVariant.name.capitalize()}" + String taskName = "reBundleAar${mVariant.name.capitalize()}" Task task = mProject.getTasks().create(taskName, Zip.class, { it.from from it.include "**"