Skip to content

Commit

Permalink
解决开启dataBinding后编译报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huangx committed Nov 12, 2020
1 parent 23ad497 commit ba00ea4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
```
buildscript {
dependencies {
classpath "cn.hx.plugin:android-junk-code:1.0.2"
classpath "cn.hx.plugin:android-junk-code:1.0.3"
}
}
```
Expand Down Expand Up @@ -41,7 +41,7 @@ android.applicationVariants.all { variant ->
}
```

### 生成文件所有目录
### 生成文件所在目录
build/generated/source/junk

### 使用插件[methodCount](https://github.com/KeepSafe/dexcount-gradle-plugin)对比
Expand Down
17 changes: 10 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'android-junk-code'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
Expand All @@ -16,7 +17,9 @@ android {
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
dataBinding = true
}
buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -46,12 +49,12 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
Expand All @@ -9,11 +9,11 @@ buildscript {
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.novoda:bintray-release:0.9.2'
classpath "cn.hx.plugin:android-junk-code:1.0.2"
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:1.0.3"
classpath "cn.hx.plugin:android-junk-code:1.0.3"
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:2.0.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jun 01 09:21:30 CST 2020
#Thu Nov 05 15:51:05 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation gradleApi()
implementation localGroovy()
implementation 'com.squareup:javapoet:1.11.1'
implementation 'com.squareup:javapoet:1.13.0'
implementation 'com.android.tools.build:gradle:3.0.0'
}

Expand Down
2 changes: 1 addition & 1 deletion library/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
project.name=AndroidJunkCode
project.groupId=cn.hx.plugin
project.artifactId=android-junk-code
project.artifactVersion=1.0.2
project.artifactVersion=1.0.3
project.siteUrl=https://github.com/qq549631030/AndroidJunkCode
project.gitUrl=https://github.com/qq549631030/AndroidJunkCode.git
project.desc=generate junk code for android
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
Closure<JunkCodeConfig> junkCodeConfig = generateJunkCodeExt.configMap[variantName]
if (junkCodeConfig) {
def dir = new File(project.buildDir, "generated/source/junk/$variantName")
def resDir = new File(dir, "res")
def javaDir = new File(dir, "java")
def manifestFile = new File(dir, "AndroidManifest.xml")
String packageName = findPackageName(variant)
def generateJunkCodeTask = project.task("generate${variantName.capitalize()}JunkCode", type: AndroidJunkCodeTask) {
junkCodeConfig.delegate = config
Expand All @@ -35,14 +38,26 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
for (int i = variant.sourceSets.size() - 1; i >= 0; i--) {
def sourceSet = variant.sourceSets[i]
if (!sourceSet.manifestFile.exists()) {
android.sourceSets."${sourceSet.name}".manifest.srcFile(new File(dir, "AndroidManifest.xml").absolutePath)
android.sourceSets."${sourceSet.name}".manifest.srcFile(manifestFile.absolutePath)
break
}
}
android.sourceSets."${variantName}".res.srcDir(new File(dir, "res"))
variant.registerJavaGeneratingTask(generateJunkCodeTask, new File(dir, "java"))
//在执行generateBuildConfig之前执行generateJunkCodeTask
variant.generateBuildConfigProvider.get().dependsOn(generateJunkCodeTask)
if (variant.respondsTo("registerGeneratedResFolders")) {
generateJunkCodeTask.ext.generatedResFolders = project
.files(resDir)
.builtBy(generateJunkCodeTask)
variant.registerGeneratedResFolders(generateJunkCodeTask.generatedResFolders)
if (variant.hasProperty("mergeResourcesProvider")) {
variant.mergeResourcesProvider.configure { dependsOn(generateJunkCodeTask) }
} else {
//noinspection GrDeprecatedAPIUsage
variant.mergeResources.dependsOn(generateJunkCodeTask)
}
} else {
//noinspection GrDeprecatedAPIUsage
variant.registerResGeneratingTask(generateJunkCodeTask, resDir)
}
variant.registerJavaGeneratingTask(generateJunkCodeTask, javaDir)
}
}
}
Expand Down

0 comments on commit ba00ea4

Please sign in to comment.