Skip to content

Commit

Permalink
生成keep.xml文件,避免开启资源压缩时生成的垃圾资源被压缩
Browse files Browse the repository at this point in the history
  • Loading branch information
qq549631030 committed Mar 30, 2023
1 parent 8333ec8 commit 99d7876
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 31
compileSdkVersion 33

defaultConfig {
applicationId "cn.hx.plugin.junkcode.demo"
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 33
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand All @@ -25,6 +25,7 @@ android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
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.2.0"
classpath "com.github.qq549631030:android-junk-code:1.2.1"
}
// 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.2.0
VERSION_NAME=1.2.1

POM_ARTIFACT_ID=android-junk-code
POM_NAME=AndroidJunkCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class AndroidJunkCodeTask extends DefaultTask {
stringList.add("${config.resPrefix.toLowerCase()}${generateName(i)}")
}
generateStringsFile()
generateKeep()
}

/**
Expand Down Expand Up @@ -235,6 +236,14 @@ class AndroidJunkCodeTask extends DefaultTask {
writeStringToFile(stringFile, sb.toString())
}

void generateKeep() {
def keepFile = new File(outDir, "res/raw/keep.xml")
StringBuilder sb = new StringBuilder()
sb.append("<resources xmlns:tools=\"http://schemas.android.com/tools\"\n" +
" tools:keep=\"@layout/${config.resPrefix}*, @drawable/${config.resPrefix}*\" />\n")
writeStringToFile(keepFile, sb.toString())
}

private void writeJavaFile(JavaFile javaFile) {
def outputDirectory = new File(outDir, "java").toPath()
if (!javaFile.packageName.isEmpty()) {
Expand Down

0 comments on commit 99d7876

Please sign in to comment.