Skip to content

Commit 99d7876

Browse files
committed
生成keep.xml文件,避免开启资源压缩时生成的垃圾资源被压缩
1 parent 8333ec8 commit 99d7876

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ apply plugin: 'com.getkeepsafe.dexcount'
77
apply plugin: 'kotlin-kapt'
88

99
android {
10-
compileSdkVersion 31
10+
compileSdkVersion 33
1111

1212
defaultConfig {
1313
applicationId "cn.hx.plugin.junkcode.demo"
1414
minSdkVersion 16
15-
targetSdkVersion 31
15+
targetSdkVersion 33
1616
versionCode 1
1717
versionName "1.0"
1818
multiDexEnabled true
@@ -25,6 +25,7 @@ android {
2525
buildTypes {
2626
release {
2727
minifyEnabled true
28+
shrinkResources true
2829
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2930
}
3031
}

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
if (PLUGIN_ENABLE.toBoolean()) {
14-
classpath "com.github.qq549631030:android-junk-code:1.2.0"
14+
classpath "com.github.qq549631030:android-junk-code:1.2.1"
1515
}
1616
// NOTE: Do not place your application dependencies here; they belong
1717
// in the individual module build.gradle files

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.2.0
3+
VERSION_NAME=1.2.1
44

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

library/src/main/groovy/cn/hx/plugin/junkcode/task/AndroidJunkCodeTask.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class AndroidJunkCodeTask extends DefaultTask {
181181
stringList.add("${config.resPrefix.toLowerCase()}${generateName(i)}")
182182
}
183183
generateStringsFile()
184+
generateKeep()
184185
}
185186

186187
/**
@@ -235,6 +236,14 @@ class AndroidJunkCodeTask extends DefaultTask {
235236
writeStringToFile(stringFile, sb.toString())
236237
}
237238

239+
void generateKeep() {
240+
def keepFile = new File(outDir, "res/raw/keep.xml")
241+
StringBuilder sb = new StringBuilder()
242+
sb.append("<resources xmlns:tools=\"http://schemas.android.com/tools\"\n" +
243+
" tools:keep=\"@layout/${config.resPrefix}*, @drawable/${config.resPrefix}*\" />\n")
244+
writeStringToFile(keepFile, sb.toString())
245+
}
246+
238247
private void writeJavaFile(JavaFile javaFile) {
239248
def outputDirectory = new File(outDir, "java").toPath()
240249
if (!javaFile.packageName.isEmpty()) {

0 commit comments

Comments
 (0)