Skip to content

Commit

Permalink
解决自动生成的混淆文件只对public类生效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
qq549631030 committed Aug 11, 2023
1 parent 45f05b2 commit 6eeb3de
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ androidJunkCode {
}
```

**注:从1.3.0开始本库已经上传到Gradle Plugin Portal 可直接这样使用**
**注:从1.3.1开始本库已经上传到Gradle Plugin Portal 可直接这样使用**

```groovy
plugins {
Expand Down Expand Up @@ -83,7 +83,7 @@ androidJunkCode {
}
```

如果APP开启了混淆,需要在混淆文件里配置 (1.3.0之后不需求配置)
如果APP开启了混淆,需要在混淆文件里配置 (1.3.1之后不需求配置)

```
#cn.hx.plugin.ui为前面配置的packageBase
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"
if (PLUGIN_ENABLE.toBoolean()) {
classpath "com.github.qq549631030:android-junk-code:1.3.1"
classpath "com.github.qq549631030:android-junk-code:1.3.2"
}
// 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,7 +1,7 @@
#project
GROUP=com.github.qq549631030
POM_ARTIFACT_ID=android-junk-code
VERSION_NAME=1.3.1
VERSION_NAME=1.3.2
POM_PACKAGING=jar

POM_NAME=AndroidJunkCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class NewVariantApiPlugin implements Plugin<Project> {
def generateJunkCodeTaskProvider = project.tasks.register("generate${variantName.capitalize()}JunkCode", GenerateJunkCodeTask) {
config = junkCodeConfig
namespace = variant.namespace
javaOutputFolder.set(junkCodeOutDir.map { it.dir("java") })
resOutputFolder.set(junkCodeOutDir.map { it.dir("res") })
manifestOutputFile.set(junkCodeOutDir.map { it.file("AndroidManifest.xml") })
proguardOutputFile.set(junkCodeOutDir.map { it.file("proguard-rules.pro") })
outputFolder.set(junkCodeOutDir)
}
if (JunkUtil.isAGP7_4_0(project)) {
if (variant.sources.java) {
Expand Down Expand Up @@ -68,12 +65,9 @@ class NewVariantApiPlugin implements Plugin<Project> {
def junkCodeConfig = generateJunkCodeExt.variantConfig.findByName(variantName)
if (junkCodeConfig) {
def generateJunkCodeTaskProvider = project.tasks.named("generate${variantName.capitalize()}JunkCode", GenerateJunkCodeTask)
variant.registerJavaGeneratingTask(generateJunkCodeTaskProvider, generateJunkCodeTaskProvider.get().javaOutputFolder.get().asFile)

variant.registerGeneratedResFolders(project.files(generateJunkCodeTaskProvider.map {
it.resOutputFolder.asFile
}).builtBy(generateJunkCodeTaskProvider))
variant.mergeResourcesProvider.configure { dependsOn(generateJunkCodeTaskProvider.get()) }
def junkCodeOutDir = project.layout.buildDirectory.dir("generated/source/junk/${variantName}")
variant.registerJavaGeneratingTask(generateJunkCodeTaskProvider, junkCodeOutDir.map { it.dir("java") }.get().asFile)
variant.registerGeneratedResFolders(project.files(junkCodeOutDir.map { it.dir("res") }.get().asFile).builtBy(generateJunkCodeTaskProvider))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ abstract class GenerateJunkCodeTask extends DefaultTask {
@Input
abstract Property<String> getNamespace()

@OutputDirectory
abstract DirectoryProperty getOutputFolder()

@OutputDirectory
abstract DirectoryProperty getJavaOutputFolder()

Expand All @@ -32,6 +35,13 @@ abstract class GenerateJunkCodeTask extends DefaultTask {
private List<String> packageList = new ArrayList<>()
private List<String> activityList = new ArrayList<>()

GenerateJunkCodeTask() {
getJavaOutputFolder().convention(getOutputFolder().dir("java"))
getResOutputFolder().convention(getOutputFolder().dir("res"))
getManifestOutputFile().convention(getOutputFolder().file("AndroidManifest.xml"))
getProguardOutputFile().convention(getOutputFolder().file("proguard-rules.pro"))
}

@TaskAction
void taskAction() {
def javaDir = getJavaOutputFolder().get().asFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class JunkUtil {
static void generateProguard(File proguardFile, List<String> packageList) {
StringBuilder sb = new StringBuilder()
for (i in 0..<packageList.size()) {
sb.append("-keep public class ${packageList.get(i)}.**{*;}\n")
sb.append("-keep class ${packageList.get(i)}.**{*;}\n")
}
writeStringToFile(proguardFile, sb.toString())
}
Expand Down

0 comments on commit 6eeb3de

Please sign in to comment.