Skip to content

Commit 9b346f5

Browse files
author
huangx
committed
适配AGP 7.3+
1 parent 5bb80a7 commit 9b346f5

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buildscript {
1111
mavenCentral()
1212
}
1313
dependencies {
14-
classpath "com.github.qq549631030:android-junk-code:1.1.2"
14+
classpath "com.github.qq549631030:android-junk-code:x.x.x"
1515
}
1616
}
1717
```
@@ -39,8 +39,6 @@ androidJunkCode {
3939
}
4040
```
4141

42-
**原configMap配置方式已过时,1.0.8版以后请使用variantConfig配置方式"**
43-
4442
如果有多个变体共用一个配置可以这样做
4543
```groovy
4644
androidJunkCode {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buildscript {
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.0.1"
1313
// classpath project(":library")
14-
classpath "com.github.qq549631030:android-junk-code:1.1.3"
14+
classpath "com.github.qq549631030:android-junk-code:1.1.4"
1515
// NOTE: Do not place your application dependencies here; they belong
1616
// in the individual module build.gradle files
1717
}

library/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#project
22
GROUP=com.github.qq549631030
3-
VERSION_NAME=1.1.3
3+
VERSION_NAME=1.1.4
44

55
POM_ARTIFACT_ID=android-junk-code
66
POM_NAME=AndroidJunkCode

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,24 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
3434
def resDir = new File(dir, "res")
3535
def javaDir = new File(dir, "java")
3636
def manifestFile = new File(dir, "AndroidManifest.xml")
37-
//从main/AndroidManifest.xml找到package name
38-
def mainManifestFile = android.sourceSets.findByName("main").manifest.srcFile
39-
def parser = new XmlParser()
40-
def node = parser.parse(mainManifestFile)
41-
def packageName = node.attribute("package")
37+
def packageName = android.namespace//AGP 7.3+
38+
if (!packageName) {//AGP under 7.3
39+
//从AndroidManifest.xml找到package name
40+
for (int i = 0; i < variant.sourceSets.size(); i++) {
41+
def sourceSet = variant.sourceSets[i]
42+
if (sourceSet.manifestFile.exists()) {
43+
def parser = new XmlParser()
44+
def node = parser.parse(sourceSet.manifestFile)
45+
packageName = node.attribute("package")
46+
if (packageName) {
47+
break
48+
}
49+
}
50+
}
51+
}
52+
if (!packageName) {
53+
packageName = ""
54+
}
4255
def generateJunkCodeTask = project.task(generateJunkCodeTaskName, type: AndroidJunkCodeTask) {
4356
config = junkCodeConfig
4457
manifestPackageName = packageName

0 commit comments

Comments
 (0)