From 9b346f57ce8b6a8ed659994937f63d9a18df6e3a Mon Sep 17 00:00:00 2001 From: huangx Date: Wed, 21 Sep 2022 14:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DAGP=207.3+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +--- build.gradle | 2 +- library/gradle.properties | 2 +- .../plugin/AndroidJunkCodePlugin.groovy | 23 +++++++++++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 17908a48..4a9f8b1c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ buildscript { mavenCentral() } dependencies { - classpath "com.github.qq549631030:android-junk-code:1.1.2" + classpath "com.github.qq549631030:android-junk-code:x.x.x" } } ``` @@ -39,8 +39,6 @@ androidJunkCode { } ``` -**原configMap配置方式已过时,1.0.8版以后请使用variantConfig配置方式"** - 如果有多个变体共用一个配置可以这样做 ```groovy androidJunkCode { diff --git a/build.gradle b/build.gradle index 4c121e41..5e57e619 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.0.1" // classpath project(":library") - classpath "com.github.qq549631030:android-junk-code:1.1.3" + classpath "com.github.qq549631030:android-junk-code:1.1.4" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/library/gradle.properties b/library/gradle.properties index 78c78f04..05bd02e1 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,6 +1,6 @@ #project GROUP=com.github.qq549631030 -VERSION_NAME=1.1.3 +VERSION_NAME=1.1.4 POM_ARTIFACT_ID=android-junk-code POM_NAME=AndroidJunkCode 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 d7fcbe25..e05b420e 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 @@ -34,11 +34,24 @@ class AndroidJunkCodePlugin implements Plugin { def resDir = new File(dir, "res") def javaDir = new File(dir, "java") def manifestFile = new File(dir, "AndroidManifest.xml") - //从main/AndroidManifest.xml找到package name - def mainManifestFile = android.sourceSets.findByName("main").manifest.srcFile - def parser = new XmlParser() - def node = parser.parse(mainManifestFile) - def packageName = node.attribute("package") + def packageName = android.namespace//AGP 7.3+ + if (!packageName) {//AGP under 7.3 + //从AndroidManifest.xml找到package name + for (int i = 0; i < variant.sourceSets.size(); i++) { + def sourceSet = variant.sourceSets[i] + if (sourceSet.manifestFile.exists()) { + def parser = new XmlParser() + def node = parser.parse(sourceSet.manifestFile) + packageName = node.attribute("package") + if (packageName) { + break + } + } + } + } + if (!packageName) { + packageName = "" + } def generateJunkCodeTask = project.task(generateJunkCodeTaskName, type: AndroidJunkCodeTask) { config = junkCodeConfig manifestPackageName = packageName