Skip to content

Commit ba00ea4

Browse files
author
huangx
committed
解决开启dataBinding后编译报错问题
1 parent 23ad497 commit ba00ea4

7 files changed

Lines changed: 40 additions & 22 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
```
1111
buildscript {
1212
dependencies {
13-
classpath "cn.hx.plugin:android-junk-code:1.0.2"
13+
classpath "cn.hx.plugin:android-junk-code:1.0.3"
1414
}
1515
}
1616
```
@@ -41,7 +41,7 @@ android.applicationVariants.all { variant ->
4141
}
4242
```
4343

44-
### 生成文件所有目录
44+
### 生成文件所在目录
4545
build/generated/source/junk
4646

4747
### 使用插件[methodCount](https://github.com/KeepSafe/dexcount-gradle-plugin)对比

app/build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'android-junk-code'
55
apply plugin: 'com.getkeepsafe.dexcount'
6+
apply plugin: 'kotlin-kapt'
67

78
android {
89
compileSdkVersion 29
@@ -16,7 +17,9 @@ android {
1617
multiDexEnabled true
1718
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1819
}
19-
20+
buildFeatures {
21+
dataBinding = true
22+
}
2023
buildTypes {
2124
release {
2225
minifyEnabled false
@@ -46,12 +49,12 @@ dependencies {
4649
implementation fileTree(dir: "libs", include: ["*.jar"])
4750
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4851
implementation 'androidx.multidex:multidex:2.0.1'
49-
implementation 'androidx.core:core-ktx:1.3.0'
50-
implementation 'androidx.appcompat:appcompat:1.1.0'
51-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
52-
testImplementation 'junit:junit:4.13'
53-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
54-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
52+
implementation 'androidx.core:core-ktx:1.3.2'
53+
implementation 'androidx.appcompat:appcompat:1.2.0'
54+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
55+
testImplementation 'junit:junit:4.13.1'
56+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
57+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
5558

5659
}
5760

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.3.72"
3+
ext.kotlin_version = "1.4.10"
44
repositories {
55
google()
66
jcenter()
@@ -9,11 +9,11 @@ buildscript {
99
}
1010
}
1111
dependencies {
12-
classpath "com.android.tools.build:gradle:4.0.0"
12+
classpath 'com.android.tools.build:gradle:4.1.0'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
classpath 'com.novoda:bintray-release:0.9.2'
15-
classpath "cn.hx.plugin:android-junk-code:1.0.2"
16-
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:1.0.3"
15+
classpath "cn.hx.plugin:android-junk-code:1.0.3"
16+
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:2.0.0"
1717

1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Jun 01 09:21:30 CST 2020
1+
#Thu Nov 05 15:51:05 CST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dependencies {
55
implementation fileTree(dir: 'libs', include: ['*.jar'])
66
implementation gradleApi()
77
implementation localGroovy()
8-
implementation 'com.squareup:javapoet:1.11.1'
8+
implementation 'com.squareup:javapoet:1.13.0'
99
implementation 'com.android.tools.build:gradle:3.0.0'
1010
}
1111

library/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
project.name=AndroidJunkCode
33
project.groupId=cn.hx.plugin
44
project.artifactId=android-junk-code
5-
project.artifactVersion=1.0.2
5+
project.artifactVersion=1.0.3
66
project.siteUrl=https://github.com/qq549631030/AndroidJunkCode
77
project.gitUrl=https://github.com/qq549631030/AndroidJunkCode.git
88
project.desc=generate junk code for android

library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
2323
Closure<JunkCodeConfig> junkCodeConfig = generateJunkCodeExt.configMap[variantName]
2424
if (junkCodeConfig) {
2525
def dir = new File(project.buildDir, "generated/source/junk/$variantName")
26+
def resDir = new File(dir, "res")
27+
def javaDir = new File(dir, "java")
28+
def manifestFile = new File(dir, "AndroidManifest.xml")
2629
String packageName = findPackageName(variant)
2730
def generateJunkCodeTask = project.task("generate${variantName.capitalize()}JunkCode", type: AndroidJunkCodeTask) {
2831
junkCodeConfig.delegate = config
@@ -35,14 +38,26 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
3538
for (int i = variant.sourceSets.size() - 1; i >= 0; i--) {
3639
def sourceSet = variant.sourceSets[i]
3740
if (!sourceSet.manifestFile.exists()) {
38-
android.sourceSets."${sourceSet.name}".manifest.srcFile(new File(dir, "AndroidManifest.xml").absolutePath)
41+
android.sourceSets."${sourceSet.name}".manifest.srcFile(manifestFile.absolutePath)
3942
break
4043
}
4144
}
42-
android.sourceSets."${variantName}".res.srcDir(new File(dir, "res"))
43-
variant.registerJavaGeneratingTask(generateJunkCodeTask, new File(dir, "java"))
44-
//在执行generateBuildConfig之前执行generateJunkCodeTask
45-
variant.generateBuildConfigProvider.get().dependsOn(generateJunkCodeTask)
45+
if (variant.respondsTo("registerGeneratedResFolders")) {
46+
generateJunkCodeTask.ext.generatedResFolders = project
47+
.files(resDir)
48+
.builtBy(generateJunkCodeTask)
49+
variant.registerGeneratedResFolders(generateJunkCodeTask.generatedResFolders)
50+
if (variant.hasProperty("mergeResourcesProvider")) {
51+
variant.mergeResourcesProvider.configure { dependsOn(generateJunkCodeTask) }
52+
} else {
53+
//noinspection GrDeprecatedAPIUsage
54+
variant.mergeResources.dependsOn(generateJunkCodeTask)
55+
}
56+
} else {
57+
//noinspection GrDeprecatedAPIUsage
58+
variant.registerResGeneratingTask(generateJunkCodeTask, resDir)
59+
}
60+
variant.registerJavaGeneratingTask(generateJunkCodeTask, javaDir)
4661
}
4762
}
4863
}

0 commit comments

Comments
 (0)