From ba00ea48849696ca770202bcb2d22a6924ca8f73 Mon Sep 17 00:00:00 2001 From: huangx Date: Thu, 12 Nov 2020 16:48:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BC=80=E5=90=AFdataBinding?= =?UTF-8?q?=E5=90=8E=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +-- app/build.gradle | 17 +++++++------ build.gradle | 8 +++--- gradle/wrapper/gradle-wrapper.properties | 4 +-- library/build.gradle | 2 +- library/project.properties | 2 +- .../plugin/AndroidJunkCodePlugin.groovy | 25 +++++++++++++++---- 7 files changed, 40 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 3eee98ec..fa9f9933 100644 --- a/README.md +++ b/README.md @@ -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" } } ``` @@ -41,7 +41,7 @@ android.applicationVariants.all { variant -> } ``` -### 生成文件所有目录 +### 生成文件所在目录 build/generated/source/junk ### 使用插件[methodCount](https://github.com/KeepSafe/dexcount-gradle-plugin)对比 diff --git a/app/build.gradle b/app/build.gradle index 462eeb5e..61ae318b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 @@ -16,7 +17,9 @@ android { multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } - + buildFeatures { + dataBinding = true + } buildTypes { release { minifyEnabled false @@ -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' } diff --git a/build.gradle b/build.gradle index d5668ec6..1224f422 100644 --- a/build.gradle +++ b/build.gradle @@ -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() @@ -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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 864ec16e..c1cc68a1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/library/build.gradle b/library/build.gradle index 7b4e1f3f..25326cf5 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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' } diff --git a/library/project.properties b/library/project.properties index d778b56a..89a141af 100644 --- a/library/project.properties +++ b/library/project.properties @@ -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 \ No newline at end of file diff --git a/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy b/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy index 19025293..b28e7b0f 100644 --- a/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy +++ b/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy @@ -23,6 +23,9 @@ class AndroidJunkCodePlugin implements Plugin { Closure 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 @@ -35,14 +38,26 @@ class AndroidJunkCodePlugin implements Plugin { 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) } } }