Skip to content

Commit

Permalink
适配AGP 7.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
huangx committed Sep 21, 2022
1 parent 5bb80a7 commit 9b346f5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand Down Expand Up @@ -39,8 +39,6 @@ androidJunkCode {
}
```

**原configMap配置方式已过时,1.0.8版以后请使用variantConfig配置方式"**

如果有多个变体共用一个配置可以这样做
```groovy
androidJunkCode {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
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
Expand Down

0 comments on commit 9b346f5

Please sign in to comment.