Skip to content

Commit

Permalink
support merge data-binding files #25 #67
Browse files Browse the repository at this point in the history
  • Loading branch information
kezong committed Sep 10, 2020
1 parent e584c4f commit 964e47e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation gradleApi()
implementation localGroovy()

implementation 'com.android.tools.build:gradle:4.0.0'
implementation 'com.android.tools.build:gradle:3.6.1'
}

//afterEvaluate {
Expand Down
2 changes: 1 addition & 1 deletion source/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
8 changes: 8 additions & 0 deletions source/src/main/groovy/com/kezong/fataar/Constants.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kezong.fataar

class Constants {

public static final String RE_BUNDLE_FOLDER = "aar_rebundle"

public static final String INTERMEDIATES_TEMP_FOLDER = "fat-r"
}
7 changes: 3 additions & 4 deletions source/src/main/groovy/com/kezong/fataar/RProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class RProcessor {
mGradlePluginVersion = version
mVersionAdapter = new VersionAdapter(project, variant, version)
// R.java dir
mJavaDir = mProject.file("${mProject.getBuildDir()}/intermediates/fat-R/r/${mVariant.dirName}")
mJavaDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r/${mVariant.dirName}")
// R.class compile dir
mClassDir = mProject.file("${mProject.getBuildDir()}/intermediates/fat-R/r-class/${mVariant.dirName}")
mClassDir = mProject.file("${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/r-class/${mVariant.dirName}")
// R.jar dir
mJarDir = mProject.file("${mProject.getBuildDir()}/outputs/aar-R/${mVariant.dirName}/libs")
mJarDir = mProject.file("${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}/${mVariant.dirName}/libs")
// aar zip file
mAarUnZipDir = mJarDir.getParentFile()
// aar output dir
Expand Down Expand Up @@ -74,7 +74,6 @@ class RProcessor {
if (f.exists()) {
f.delete()
}
mJarDir.getParentFile().deleteDir()
mJarDir.mkdirs()
}

Expand Down
42 changes: 40 additions & 2 deletions source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,53 @@ class VariantProcessor {
processAssets()
processJniLibs()
processProguardTxt(prepareTask)
processR(bundleTask)
processDataBinding(bundleTask)
}

private void processR(TaskProvider<Task> bundleTask) {
RProcessor rProcessor = new RProcessor(mProject, mVariant, mAndroidArchiveLibraries, mGradlePluginVersion)
rProcessor.inject(bundleTask)
}

private void processDataBinding(TaskProvider<Task> bundleTask) {
bundleTask.configure {
doFirst {
for (archiveLibrary in mAndroidArchiveLibraries) {
if (archiveLibrary.dataBindingFolder != null && archiveLibrary.dataBindingFolder.exists()) {
String filePath = "${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}" +
"/${mVariant.dirName}/${archiveLibrary.dataBindingFolder.name}"
new File(filePath).mkdirs()
mProject.copy {
from archiveLibrary.dataBindingFolder
into filePath
}
}

if (archiveLibrary.dataBindingLogFolder != null && archiveLibrary.dataBindingLogFolder.exists()) {
String filePath = "${mProject.getBuildDir()}/outputs/${Constants.RE_BUNDLE_FOLDER}/${mVariant.dirName}" +
"/${archiveLibrary.dataBindingLogFolder.name}"
new File(filePath).mkdirs()
mProject.copy {
from archiveLibrary.dataBindingLogFolder
into filePath
}
}
}
}
}
}

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()
}
}

/**
Expand Down Expand Up @@ -170,7 +208,7 @@ class VariantProcessor {
*/
private void processManifest() {
Task processManifestTask = mVersionAdapter.getProcessManifest()
String manifestInputDir = "${mProject.getBuildDir()}/intermediates/fat-R/manifest"
String manifestInputDir = "${mProject.getBuildDir()}/intermediates/${Constants.INTERMEDIATES_TEMP_FOLDER}/manifest"
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")
Expand All @@ -184,7 +222,7 @@ class VariantProcessor {
// 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ public String getPackageName() {
}
return packageName;
}

public File getDataBindingFolder() {
return new File(getRootFolder(), "data-binding");
}

public File getDataBindingLogFolder() {
return new File(getRootFolder(), "data-binding-base-class-log");
}
}

0 comments on commit 964e47e

Please sign in to comment.