From ffc4e34f61e8a4b7510dbfe5fe397e11e12b8e9c Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Wed, 11 Aug 2021 13:24:54 +0800 Subject: [PATCH 01/17] V.0.1.10 --- core/build.gradle | 14 +++++++------- .../parser/ResourcesMappingParser.java | 1 + gradle.properties | 6 +++--- gradle/versions.gradle | 11 ++++++----- gradle/wrapper/gradle-wrapper.properties | 8 ++------ .../android/plugin/tasks/AabResGuardTask.kt | 18 +++++++++++++++--- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index ce3725e..7edac6b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -6,7 +6,7 @@ buildscript { } } dependencies { - classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.8" + classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.13" } } @@ -30,24 +30,24 @@ dependencies { compileOnly "com.android.tools.build:aapt2-proto:0.4.0" compileOnly gradleApi() -// compile deps.gradle.agp + // compile deps.gradle.agp implementation "com.android.support:support-annotations:24.2.0" - shadow 'commons-io:commons-io:2.6' + shadow 'commons-io:commons-io:2.7' shadow 'commons-codec:commons-codec:1.5' - shadow "com.google.guava:guava:27.0.1-jre" + shadow "com.google.guava:guava:30.0-jre" annotationProcessor "com.google.auto.value:auto-value:1.5.2" implementation "com.google.auto.value:auto-value:1.5.2" - shadow group: 'org.dom4j', name: 'dom4j', version: '2.1.0' + shadow group: 'org.dom4j', name: 'dom4j', version: '2.1.1' shadow deps.bundletool testImplementation deps.gradle.agp testImplementation "com.android.tools.build:aapt2-proto:0.4.0" - testImplementation group: 'org.dom4j', name: 'dom4j', version: '2.1.0' + testImplementation group: 'org.dom4j', name: 'dom4j', version: '2.1.1' testImplementation "junit:junit:4.12" testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0" - testImplementation "com.google.guava:guava:27.0.1-jre" + testImplementation "com.google.guava:guava:30.0-jre" testImplementation "org.mockito:mockito-core:2.18.3" testImplementation "com.google.truth.extensions:truth-java8-extension:0.45" testImplementation "com.google.truth.extensions:truth-proto-extension:0.45" diff --git a/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java b/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java index ef3901d..d8758bf 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java @@ -36,6 +36,7 @@ public ResourcesMapping parse() throws IOException { line = br.readLine(); continue; } + System.out.println("Res: "+line); if (!line.contains(":")) { Matcher mat = MAP_DIR_PATTERN.matcher(line); if (mat.find()) { diff --git a/gradle.properties b/gradle.properties index 15aae33..a067f45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,11 +21,11 @@ RELEASE_REPOSITORY_URL= SNAPSHOT_REPOSITORY_URL= PUBLISH_LOCAL_REPO=../repo # 是否使用本地 maven 依赖 -useLocalMaven=false +useLocalMaven=true # 是否源码依赖 -useSource=false +useSource=true enableAabResGuardPlugin=true # bintray -uploadToBintray=true +uploadToBintray=false bintrayInfo.user=**** bintrayInfo.apiKey=*************** diff --git a/gradle/versions.gradle b/gradle/versions.gradle index 58a336d..8e7d6ac 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -1,15 +1,15 @@ def versions = [:] -versions.agp = "4.1.0" +versions.agp = "4.2.0" versions.kotlin = "1.3.61" versions.java = "8" -versions.aabresguard = "0.1.9" +versions.aabresguard = "0.1.10" // android -versions.compileSdkVersion = 28 +versions.compileSdkVersion = 30//28 versions.minSdkVersion = 15 -versions.targetSdkVersion = 28 +versions.targetSdkVersion = 30//28 versions.support = "28.0.0" -versions.bundletool = "0.10.0" +versions.bundletool = "0.12.0" versions["aabresguard-core"] = versions.aabresguard versions["aabresguard-plugin"] = versions.aabresguard @@ -22,6 +22,7 @@ versions.digital = "3.4.0" ext.versions = versions ext.deps = [:] + // gradle def gradle = [:] gradle.agp = "com.android.tools.build:gradle:${versions.agp}" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 46ec2ea..78f6d1c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,10 +1,6 @@ -#Tue Oct 15 17:54:10 CST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +#distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -#distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip -#distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip -#distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-milestone-2-all.zip -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip -#distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip diff --git a/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt b/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt index cb411e8..dffac3b 100644 --- a/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt +++ b/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt @@ -8,20 +8,30 @@ import com.bytedance.android.plugin.internal.getBundleFilePath import com.bytedance.android.plugin.internal.getSigningConfig import com.bytedance.android.plugin.model.SigningConfig import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* import java.io.File import java.nio.file.Path /** * Created by YangJing on 2019/10/15 . * Email: yangjing.yeoh@bytedance.com + * Modified 2021/08/11 */ open class AabResGuardTask : DefaultTask() { + @get:Internal private lateinit var variant: ApplicationVariant + + @get:Internal lateinit var signingConfig: SigningConfig + + @get:Internal var aabResGuard: AabResGuardExtension = project.extensions.getByName("aabResGuard") as AabResGuardExtension + + @get:Internal private lateinit var bundlePath: Path + + @get:Internal private lateinit var obfuscatedBundlePath: Path init { @@ -36,11 +46,13 @@ open class AabResGuardTask : DefaultTask() { bundlePath = getBundleFilePath(project, variant) obfuscatedBundlePath = File(bundlePath.toFile().parentFile, aabResGuard.obfuscatedBundleFileName).toPath() } - +/* + @InputFile + @Optional fun getObfuscatedBundlePath(): Path { return obfuscatedBundlePath } - +*/ @TaskAction private fun execute() { println(aabResGuard.toString()) From a3e280132aefe916a0b68d52c757ce88b29e7575 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Wed, 11 Aug 2021 13:28:51 +0800 Subject: [PATCH 02/17] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bfab48d..90d1fed 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -# AabResGuard +# AabResGuard - MartinLoren Edition

The tool of obfuscated aab resources

-[ ![Download](https://api.bintray.com/packages/yeoh/maven/aabresguard-core/images/download.svg) ](https://bintray.com/yeoh/maven/aabresguard-plugin/) +[Download V.0.1.10](https://github.com/martinloren/mvn-repo/raw/main/AabResGuard_0.1.10.zip) + [![License](https://img.shields.io/badge/license-Apache2.0-brightgreen)](LICENSE) [![Bundletool](https://img.shields.io/badge/Dependency-Bundletool/0.10.0-blue)](https://github.com/google/bundletool) From 0578476e63c17d7fcaa42eeb3d03756cf6112e03 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Wed, 11 Aug 2021 13:29:46 +0800 Subject: [PATCH 03/17] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 90d1fed..0e26651 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,12 @@ Configured in `build.gradle(root project)` buildscript { repositories { mavenCentral() + mavenLocal() jcenter() google() } dependencies { - classpath "com.bytedance.android:aabresguard-plugin:0.1.0" + classpath "com.bytedance.android:aabresguard-plugin:0.1.10" } } ``` @@ -51,7 +52,7 @@ Configured in `build.gradle(application)` ```gradle apply plugin: "com.bytedance.android.aabResGuard" aabResGuard { - mappingFile = file("mapping.txt").toPath() // Mapping file used for incremental obfuscation + //mappingFile = file("mapping.txt").toPath() // Mapping file used for incremental obfuscation whiteList = [ // White list rules "*.R.raw.*", "*.R.drawable.icon" From 9c3629b5800de22e93b947472c86f178117e0e6e Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Wed, 11 Aug 2021 13:33:58 +0800 Subject: [PATCH 04/17] Update OpenJDKJarSigner.java --- .../bytedance/android/aabresguard/android/OpenJDKJarSigner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/android/OpenJDKJarSigner.java b/core/src/main/java/com/bytedance/android/aabresguard/android/OpenJDKJarSigner.java index 0fda889..da0978e 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/android/OpenJDKJarSigner.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/android/OpenJDKJarSigner.java @@ -71,7 +71,7 @@ public void sign(File toBeSigned, JarSigner.Signature signature) throws IOExcept throw new RuntimeException( String.format("%s failed with exit code %d: \n %s", jarSignerExecutable, exitCode, - errors.trim().isEmpty() ? errors : output + errors.trim().isEmpty() ? output : errors ) ); } From a562d4bd83c2cc3512aed9319c255a2b5243b6cb Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Sat, 14 Aug 2021 10:21:04 +0800 Subject: [PATCH 05/17] updated --- core/gitignore | 1 + gitignore | 9 +++++++++ plugin/gitignore | 1 + travis.yml | 4 ++++ 4 files changed, 15 insertions(+) create mode 100644 core/gitignore create mode 100644 gitignore create mode 100644 plugin/gitignore create mode 100644 travis.yml diff --git a/core/gitignore b/core/gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/core/gitignore @@ -0,0 +1 @@ +/build diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..e02c262 --- /dev/null +++ b/gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea +.DS_Store +/build +/captures +.externalNativeBuild +/repo \ No newline at end of file diff --git a/plugin/gitignore b/plugin/gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/plugin/gitignore @@ -0,0 +1 @@ +/build diff --git a/travis.yml b/travis.yml new file mode 100644 index 0000000..ac3018d --- /dev/null +++ b/travis.yml @@ -0,0 +1,4 @@ +language: java +script: "./gradlew check" +jdk: + - oraclejdk8 From a824d6082da134cc1ef8ca42b8b9d972a06f6ec0 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:07:33 +0800 Subject: [PATCH 06/17] Fixed PNG files --- samples/app/src/main/res/drawable/ic_abc.png | Bin 0 -> 109 bytes samples/app/src/main/res/drawable/ic_bcd.png | Bin 0 -> 109 bytes samples/app/src/main/res/drawable/ic_keep.png | Bin 0 -> 109 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/samples/app/src/main/res/drawable/ic_abc.png b/samples/app/src/main/res/drawable/ic_abc.png index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b9d310c9103991a26764dacab462ca493ced76e7 100644 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X_&r@5Ln>}1{rLai-l2h!f%PBLKizYk?|@Pap00i_>zopr E0IK63`v3p{ literal 0 HcmV?d00001 diff --git a/samples/app/src/main/res/drawable/ic_bcd.png b/samples/app/src/main/res/drawable/ic_bcd.png index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b9d310c9103991a26764dacab462ca493ced76e7 100644 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X_&r@5Ln>}1{rLai-l2h!f%PBLKizYk?|@Pap00i_>zopr E0IK63`v3p{ literal 0 HcmV?d00001 diff --git a/samples/app/src/main/res/drawable/ic_keep.png b/samples/app/src/main/res/drawable/ic_keep.png index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b9d310c9103991a26764dacab462ca493ced76e7 100644 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X_&r@5Ln>}1{rLai-l2h!f%PBLKizYk?|@Pap00i_>zopr E0IK63`v3p{ literal 0 HcmV?d00001 From 16dd2d5e0b12175157930b56025101986267bb21 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:08:02 +0800 Subject: [PATCH 07/17] FIxed english, remove deprecated jcenter repo --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 8762284..0f43f54 100644 --- a/build.gradle +++ b/build.gradle @@ -4,12 +4,12 @@ buildscript { apply from: rootProject.file("gradle/config.gradle") repositories { google() - jcenter() + //jcenter() if ("true".equalsIgnoreCase(System.getProperty('useLocalMaven', "false"))) { - println "use local repo" + println "Using local repo." mavenLocal() } else { - println "use remove repo" + println "Using remote repo." maven { url findProperty("RELEASE_REPOSITORY_URL") } maven { url findProperty("SNAPSHOT_REPOSITORY_URL") } } From 76414097e36692d8a48243551dfb6229b23788f5 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:08:45 +0800 Subject: [PATCH 08/17] Auto delete old log and mapping files --- .../executors/DuplicatedResourcesMerger.java | 8 +++++++- .../aabresguard/executors/ResourcesObfuscator.java | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java index ba2fa55..c71c963 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java @@ -17,6 +17,8 @@ import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -89,7 +91,11 @@ public AppBundle merge() throws IOException { */ private BundleModule mergeBundleModule(BundleModule bundleModule) throws IOException { File logFile = new File(outputLogLocationDir.toFile(), bundleModule.getName().getName() + SUFFIX_FILE_DUPLICATED_LOGGER); - checkFileDoesNotExist(logFile.toPath()); + //checkFileDoesNotExist(logFile.toPath()); + if (Files.exists(logFile.toPath(), new LinkOption[0])) { + logger.warning("Log file: "+logFile.toPath()+" already existing! Deleting..."); + Files.delete(logFile.toPath()); + } Resources.ResourceTable table = bundleModule.getResourceTable().orElse(Resources.ResourceTable.getDefaultInstance()); if (table.getPackageList().isEmpty() || bundleModule.getEntries().isEmpty()) { diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java index ce16072..c21b0bf 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java @@ -22,6 +22,8 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -37,6 +39,8 @@ import java.util.stream.Stream; import java.util.zip.ZipFile; +import groovy.util.logging.Log; + import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist; import static com.bytedance.android.aabresguard.bundle.AppBundleUtils.getEntryNameByResourceName; import static com.bytedance.android.aabresguard.bundle.AppBundleUtils.getTypeNameByResourceName; @@ -71,7 +75,11 @@ public ResourcesObfuscator(Path bundlePath, AppBundle rawAppBundle, Set this.bundleZipFile = new ZipFile(bundlePath.toFile()); outputMappingPath = new File(outputLogLocationDir.toFile(), FILE_MAPPING_NAME).toPath(); - checkFileDoesNotExist(outputMappingPath); + //checkFileDoesNotExist(outputMappingPath); + if (Files.exists(outputMappingPath, new LinkOption[0])) { + logger.warning("Mapping file: "+outputMappingPath+" already existing! Deleting..."); + Files.delete(outputMappingPath); + } this.rawAppBundle = rawAppBundle; this.whiteListRules = whiteListRules; From 0de0992ae630be579d8fbbf9d266c5039ce8a01f Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:09:10 +0800 Subject: [PATCH 09/17] Better logging --- .../plugin/extensions/AabResGuardExtension.kt | 2 +- .../android/plugin/tasks/AabResGuardTask.kt | 35 +++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/plugin/src/main/kotlin/com/bytedance/android/plugin/extensions/AabResGuardExtension.kt b/plugin/src/main/kotlin/com/bytedance/android/plugin/extensions/AabResGuardExtension.kt index d78e91e..cf78553 100644 --- a/plugin/src/main/kotlin/com/bytedance/android/plugin/extensions/AabResGuardExtension.kt +++ b/plugin/src/main/kotlin/com/bytedance/android/plugin/extensions/AabResGuardExtension.kt @@ -19,7 +19,7 @@ open class AabResGuardExtension { var languageWhiteList: Set? = HashSet() override fun toString(): String { - return "AabResGuardExtension\n" + + return "-------------- AabResGuardExtension --------------\n" + "\tenableObfuscate=$enableObfuscate" + "\tmappingFile=$mappingFile" + "\twhiteList=${if (whiteList == null) null else whiteList}\n" + diff --git a/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt b/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt index dffac3b..caba09c 100644 --- a/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt +++ b/plugin/src/main/kotlin/com/bytedance/android/plugin/tasks/AabResGuardTask.kt @@ -10,14 +10,20 @@ import com.bytedance.android.plugin.model.SigningConfig import org.gradle.api.DefaultTask import org.gradle.api.tasks.* import java.io.File +import java.lang.System.out import java.nio.file.Path +import org.gradle.internal.logging.text.StyledTextOutput +import org.gradle.internal.logging.text.StyledTextOutputFactory +import org.gradle.internal.logging.text.StyledTextOutput.Style +import javax.inject.Inject +import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType /** * Created by YangJing on 2019/10/15 . * Email: yangjing.yeoh@bytedance.com * Modified 2021/08/11 */ -open class AabResGuardTask : DefaultTask() { +open class AabResGuardTask @Inject constructor(outputFactory: StyledTextOutputFactory) : DefaultTask() { @get:Internal private lateinit var variant: ApplicationVariant @@ -53,12 +59,15 @@ open class AabResGuardTask : DefaultTask() { return obfuscatedBundlePath } */ + private val out = outputFactory.create("AabResGuardTask") + @TaskAction private fun execute() { - println(aabResGuard.toString()) + out.style(Style.Info).println(aabResGuard.toString()) // init signing config signingConfig = getSigningConfig(project, variant) printSignConfiguration() + printOutputFileLocation() prepareUnusedFile() @@ -96,22 +105,28 @@ open class AabResGuardTask : DefaultTask() { if (aabResGuard.enableFilterStrings) { if (aabResGuard.unusedStringPath == null || aabResGuard.unusedStringPath!!.isBlank()) { aabResGuard.unusedStringPath = usedFile.absolutePath - println("replace unused.txt!") + out.style(Style.Error).println("replace unused.txt!") } } } else { - println("not exists unused.txt : ${usedFile.absolutePath}\n" + + out.style(Style.Error).println("not exists unused.txt : ${usedFile.absolutePath}\n" + "use default path : ${aabResGuard.unusedStringPath}") } } private fun printSignConfiguration() { - println("-------------- sign configuration --------------") - println("\tstoreFile : ${signingConfig.storeFile}") - println("\tkeyPassword : ${encrypt(signingConfig.keyPassword)}") - println("\talias : ${encrypt(signingConfig.keyAlias)}") - println("\tstorePassword : ${encrypt(signingConfig.storePassword)}") - println("-------------- sign configuration --------------") + println("-------------- Sign configuration --------------") + println("\tStoreFile:\t\t${signingConfig.storeFile}") + println("\tKeyPassword:\t${encrypt(signingConfig.keyPassword)}") + println("\tAlias:\t\t\t${encrypt(signingConfig.keyAlias)}") + println("\tStorePassword:\t${encrypt(signingConfig.storePassword)}") + } + + private fun printOutputFileLocation() { + println("-------------- Output configuration --------------") + println("\tFolder:\t\t${obfuscatedBundlePath.parent}") + println("\tFile:\t\t${obfuscatedBundlePath.fileName}") + println("--------------------------------------------------") } private fun encrypt(value: String?): String { From 88cc10c9e0683f37ace0b2d0526d19baaeb6ecc3 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Mon, 16 Aug 2021 21:53:43 +0800 Subject: [PATCH 10/17] Corrected typo --- .../android/aabresguard/bundle/AppBundleAnalyzer.java | 2 +- .../android/aabresguard/bundle/AppBundlePackager.java | 2 +- .../android/aabresguard/bundle/AppBundleSigner.java | 3 +-- .../commands/DuplicatedResourcesMergerCommand.java | 4 ++-- .../android/aabresguard/commands/FileFilterCommand.java | 4 ++-- .../aabresguard/commands/ObfuscateBundleCommand.java | 5 ++--- .../android/aabresguard/commands/StringFilterCommand.java | 4 ++-- .../android/aabresguard/executors/BundleFileFilter.java | 6 +++--- .../android/aabresguard/executors/BundleStringFilter.java | 4 ++-- .../aabresguard/executors/DuplicatedResourcesMerger.java | 4 ++-- .../android/aabresguard/executors/ResourcesObfuscator.java | 7 ++----- .../com/bytedance/android/aabresguard/utils/TimeClock.java | 2 +- .../android/aabresguard/utils/FileOperationTest.java | 2 +- wiki/en/DATA.md | 2 +- 14 files changed, 23 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java index b43b702..a73aee0 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java @@ -28,7 +28,7 @@ public AppBundle analyze() throws IOException { TimeClock timeClock = new TimeClock(); ZipFile bundleZip = new ZipFile(bundlePath.toFile()); AppBundle appBundle = AppBundle.buildFromZip(bundleZip); - System.out.println(String.format("analyze bundle file done, const %s", timeClock.getCoast())); + System.out.println(String.format("analyze bundle file done, const %s", timeClock.getCost())); return appBundle; } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java index 17164f9..b1c6ea9 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java @@ -31,6 +31,6 @@ public void execute() throws IOException { AppBundleSerializer appBundleSerializer = new AppBundleSerializer(); appBundleSerializer.writeToDisk(appBundle, output); - System.out.println(String.format("package bundle done, coast: %s", timeClock.getCoast())); + System.out.println(String.format("package bundle done, cost: %s", timeClock.getCost())); } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java index 0f549ef..8553d35 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.logging.Logger; /** * Created by YangJing on 2019/10/11 . @@ -41,6 +40,6 @@ public void execute() throws IOException, InterruptedException { bundleSignature.keyPassword ); new JarSigner().sign(bundleFile.toFile(), signature); - System.out.println(String.format("[sign] sign done, coast: %s", timeClock.getCoast())); + System.out.println(String.format("[sign] sign done, cost: %s", timeClock.getCost())); } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java index 7ce45f4..5fc6e61 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java @@ -141,11 +141,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "duplicate resources done, coast %s\n" + + "duplicate resources done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle file size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java index aede102..3c002e6 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java @@ -169,11 +169,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "filter bundle files done, coast %s\n" + + "filter bundle files done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle file size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java index e027ec3..7a8212f 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java @@ -28,7 +28,6 @@ import java.util.Set; import java.util.logging.Logger; -import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist; import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable; import static com.bytedance.android.aabresguard.utils.FileOperation.getNetFileSizeDescription; import static com.bytedance.android.aabresguard.utils.exception.CommandExceptionPreconditions.checkFlagPresent; @@ -234,11 +233,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "obfuscate resources done, coast %s\n" + + "obfuscate resources done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle file size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java index f832f62..15938d1 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java @@ -145,11 +145,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "filter bundle strings done, coast %s\n" + + "filter bundle strings done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle string size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java index cba042a..ba85df9 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java @@ -80,12 +80,12 @@ public AppBundle filter() throws IOException { .setModules(ImmutableMap.copyOf(bundleModules)) .build(); System.out.println(String.format( - "filter bundle files done, coast %s" + + "filter bundle files done, cost %s\n" + "-----------------------------------------\n" + "Reduce file count: %s\n" + "Reduce file size: %s\n" + - "-----------------------------------------", - timeClock.getCoast(), + "-----------------------------------------\n", + timeClock.getCost(), filterTotalCount, getNetFileSizeDescription(filterTotalSize) )); diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java index 7a5df48..af0baf3 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java @@ -75,8 +75,8 @@ public AppBundle filter() throws IOException { .build(); System.out.println(String.format( - "filtering strings done, coast %s\n", - timeClock.getCoast() + "filtering strings done, cost %s\n", + timeClock.getCost() )); return appBundle; diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java index c71c963..611bd2c 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java @@ -74,12 +74,12 @@ public AppBundle merge() throws IOException { ); System.out.println(String.format( - "merge duplicated resources done, coast %s\n" + + "merge duplicated resources done, cost %s\n" + "-----------------------------------------\n" + "Reduce file count: %s\n" + "Reduce file size: %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), mergeDuplicatedTotalCount, getNetFileSizeDescription(mergeDuplicatedTotalSize) )); diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java index c21b0bf..aff69e2 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java @@ -39,9 +39,6 @@ import java.util.stream.Stream; import java.util.zip.ZipFile; -import groovy.util.logging.Log; - -import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist; import static com.bytedance.android.aabresguard.bundle.AppBundleUtils.getEntryNameByResourceName; import static com.bytedance.android.aabresguard.bundle.AppBundleUtils.getTypeNameByResourceName; import static com.bytedance.android.aabresguard.bundle.ResourcesTableOperation.checkConfiguration; @@ -115,8 +112,8 @@ public AppBundle obfuscate() throws IOException { .build(); System.out.println(String.format( - "obfuscate resources done, coast %s", - timeClock.getCoast() + "obfuscate resources done, cost %s", + timeClock.getCost() )); // write mapping rules to file. diff --git a/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java b/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java index b77c859..dc82c85 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java @@ -12,7 +12,7 @@ public TimeClock() { startTime = System.currentTimeMillis(); } - public String getCoast() { + public String getCost() { return (System.currentTimeMillis() - startTime) + ""; } } diff --git a/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java b/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java index a621b50..2490571 100644 --- a/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java +++ b/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java @@ -23,7 +23,7 @@ public void testUnZip() throws IOException { Path unzipDirPath = getTempDirPath(); Path targetDir = new File(getTempDirPath().toFile(), "/aab").toPath(); FileOperation.uncompress(aabFile.toPath(), targetDir); - System.out.println("testUnZip method coast:"); + System.out.println("testUnZip method cost:"); FileOperation.uncompress(aabFile.toPath(), unzipDirPath); } diff --git a/wiki/en/DATA.md b/wiki/en/DATA.md index d782cc2..71c5bc0 100644 --- a/wiki/en/DATA.md +++ b/wiki/en/DATA.md @@ -12,7 +12,7 @@ The current data of size savings for multiple products is below: **AabResGuard-0.1.0** -|App|coast time|aab size|apk raw size|apk download size| +|App|cost time|aab size|apk raw size|apk download size| |---|-------|--------|-------------|----------------| |Tiktok/840|75s|-2.9MB|-1.9MB|-0.7MB| |Vigo/v751|60s|-1.0Mb|-1.4MB|-0.6MB| From a333787541830d4cca834c401458e9aa92a27a91 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Wed, 18 Aug 2021 10:15:36 +0800 Subject: [PATCH 11/17] Corrected typo --- .../aabresguard/executors/ResourcesObfuscator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java index aff69e2..046e238 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java @@ -179,23 +179,25 @@ private void generateResourceMappingRule(BundleModule bundleModule, Map obfuscateModuleEntries(BundleModule bundleModule, Ma String bundleRawPath = bundleModule.getName().getName() + "/" + entry.getPath().toString(); String bundleObfuscatedPath = resourcesMapping.getEntryFilesMapping().get(bundleRawPath); if (bundleObfuscatedPath == null) { + //System.out.println(": "+bundleRawPath); if (!shouldBeObfuscated(bundleRawPath)) { System.out.println(String.format( "[whiteList] find whiteList resource file, resource: %s", @@ -242,6 +245,7 @@ private Map obfuscateModuleEntries(BundleModule bundleModule, Ma String obfuscatedName = guardStringBuilder.getReplaceString(mapping); mapping.add(obfuscatedName); bundleObfuscatedPath = obfuscateDir + "/" + obfuscatedName + fileSuffix; + //System.out.println(" -> "+bundleObfuscatedPath); resourcesMapping.putEntryFileMapping(bundleRawPath, bundleObfuscatedPath); } } From 7e160fa3773d3f61b13b75aeddb9115c82cab1cd Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Wed, 18 Aug 2021 10:54:52 +0800 Subject: [PATCH 12/17] Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e26651..863fc8c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ > Powered by bytedance douyin android team. -## Features +## Features$$ > The tool of obfuscated aab resources. - **Merge duplicated resources:** Consolidate duplicate resource files to reduce package size. @@ -55,7 +55,21 @@ aabResGuard { //mappingFile = file("mapping.txt").toPath() // Mapping file used for incremental obfuscation whiteList = [ // White list rules "*.R.raw.*", - "*.R.drawable.icon" + "*.R.drawable.icon", + // Google-services & Firebase + "*.R.string.google_app_id", + "*.R.string.gcm_defaultSenderId", + "*.R.string.default_web_client_id", + "*.R.string.ga_trackingId", + "*.R.string.firebase_database_url", + "*.R.string.google_api_key", + "*.R.string.google_crash_reporting_api_key", + "*.R.string.default_web_client_id", + "*.R.string.gcm_defaultSenderId", + "*.R.string.google_app_id", + "*.R.string.google_crash_reporting_api_key", + "*.R.string.google_storage_bucket", + "*.R.string.project_id" ] obfuscatedBundleFileName = "duplicated-app.aab" // Obfuscated file name, must end with '.aab' mergeDuplicatedRes = true // Whether to allow the merge of duplicate resources From 52e42b21eaff16aa738cadd4a1c3e6a44bd145ee Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Fri, 15 Oct 2021 09:50:28 +0800 Subject: [PATCH 13/17] Updated --- README.md | 18 ++++++++++++++++-- .../aabresguard/bundle/AppBundleAnalyzer.java | 2 +- .../aabresguard/bundle/AppBundlePackager.java | 2 +- .../aabresguard/bundle/AppBundleSigner.java | 3 +-- .../DuplicatedResourcesMergerCommand.java | 4 ++-- .../commands/FileFilterCommand.java | 4 ++-- .../commands/ObfuscateBundleCommand.java | 5 ++--- .../commands/StringFilterCommand.java | 4 ++-- .../executors/BundleFileFilter.java | 6 +++--- .../executors/BundleStringFilter.java | 4 ++-- .../executors/DuplicatedResourcesMerger.java | 4 ++-- .../executors/ResourcesObfuscator.java | 15 ++++++++------- .../android/aabresguard/utils/TimeClock.java | 2 +- .../aabresguard/utils/FileOperationTest.java | 2 +- wiki/en/DATA.md | 2 +- 15 files changed, 45 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 0e26651..863fc8c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ > Powered by bytedance douyin android team. -## Features +## Features$$ > The tool of obfuscated aab resources. - **Merge duplicated resources:** Consolidate duplicate resource files to reduce package size. @@ -55,7 +55,21 @@ aabResGuard { //mappingFile = file("mapping.txt").toPath() // Mapping file used for incremental obfuscation whiteList = [ // White list rules "*.R.raw.*", - "*.R.drawable.icon" + "*.R.drawable.icon", + // Google-services & Firebase + "*.R.string.google_app_id", + "*.R.string.gcm_defaultSenderId", + "*.R.string.default_web_client_id", + "*.R.string.ga_trackingId", + "*.R.string.firebase_database_url", + "*.R.string.google_api_key", + "*.R.string.google_crash_reporting_api_key", + "*.R.string.default_web_client_id", + "*.R.string.gcm_defaultSenderId", + "*.R.string.google_app_id", + "*.R.string.google_crash_reporting_api_key", + "*.R.string.google_storage_bucket", + "*.R.string.project_id" ] obfuscatedBundleFileName = "duplicated-app.aab" // Obfuscated file name, must end with '.aab' mergeDuplicatedRes = true // Whether to allow the merge of duplicate resources diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java index b43b702..a73aee0 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java @@ -28,7 +28,7 @@ public AppBundle analyze() throws IOException { TimeClock timeClock = new TimeClock(); ZipFile bundleZip = new ZipFile(bundlePath.toFile()); AppBundle appBundle = AppBundle.buildFromZip(bundleZip); - System.out.println(String.format("analyze bundle file done, const %s", timeClock.getCoast())); + System.out.println(String.format("analyze bundle file done, const %s", timeClock.getCost())); return appBundle; } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java index 17164f9..b1c6ea9 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundlePackager.java @@ -31,6 +31,6 @@ public void execute() throws IOException { AppBundleSerializer appBundleSerializer = new AppBundleSerializer(); appBundleSerializer.writeToDisk(appBundle, output); - System.out.println(String.format("package bundle done, coast: %s", timeClock.getCoast())); + System.out.println(String.format("package bundle done, cost: %s", timeClock.getCost())); } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java index 0f549ef..8553d35 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleSigner.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.logging.Logger; /** * Created by YangJing on 2019/10/11 . @@ -41,6 +40,6 @@ public void execute() throws IOException, InterruptedException { bundleSignature.keyPassword ); new JarSigner().sign(bundleFile.toFile(), signature); - System.out.println(String.format("[sign] sign done, coast: %s", timeClock.getCoast())); + System.out.println(String.format("[sign] sign done, cost: %s", timeClock.getCost())); } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java index 7ce45f4..5fc6e61 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/DuplicatedResourcesMergerCommand.java @@ -141,11 +141,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "duplicate resources done, coast %s\n" + + "duplicate resources done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle file size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java index aede102..3c002e6 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/FileFilterCommand.java @@ -169,11 +169,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "filter bundle files done, coast %s\n" + + "filter bundle files done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle file size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java index e027ec3..7a8212f 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java @@ -28,7 +28,6 @@ import java.util.Set; import java.util.logging.Logger; -import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist; import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable; import static com.bytedance.android.aabresguard.utils.FileOperation.getNetFileSizeDescription; import static com.bytedance.android.aabresguard.utils.exception.CommandExceptionPreconditions.checkFlagPresent; @@ -234,11 +233,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "obfuscate resources done, coast %s\n" + + "obfuscate resources done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle file size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java index f832f62..15938d1 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/StringFilterCommand.java @@ -145,11 +145,11 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() long rawSize = FileOperation.getFileSizes(getBundlePath().toFile()); long filteredSize = FileOperation.getFileSizes(getOutputPath().toFile()); System.out.println(String.format( - "filter bundle strings done, coast %s\n" + + "filter bundle strings done, cost %s\n" + "-----------------------------------------\n" + "Reduce bundle string size: %s, %s -> %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), getNetFileSizeDescription(rawSize - filteredSize), getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java index cba042a..ba85df9 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleFileFilter.java @@ -80,12 +80,12 @@ public AppBundle filter() throws IOException { .setModules(ImmutableMap.copyOf(bundleModules)) .build(); System.out.println(String.format( - "filter bundle files done, coast %s" + + "filter bundle files done, cost %s\n" + "-----------------------------------------\n" + "Reduce file count: %s\n" + "Reduce file size: %s\n" + - "-----------------------------------------", - timeClock.getCoast(), + "-----------------------------------------\n", + timeClock.getCost(), filterTotalCount, getNetFileSizeDescription(filterTotalSize) )); diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java index 7a5df48..af0baf3 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/BundleStringFilter.java @@ -75,8 +75,8 @@ public AppBundle filter() throws IOException { .build(); System.out.println(String.format( - "filtering strings done, coast %s\n", - timeClock.getCoast() + "filtering strings done, cost %s\n", + timeClock.getCost() )); return appBundle; diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java index c71c963..611bd2c 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/DuplicatedResourcesMerger.java @@ -74,12 +74,12 @@ public AppBundle merge() throws IOException { ); System.out.println(String.format( - "merge duplicated resources done, coast %s\n" + + "merge duplicated resources done, cost %s\n" + "-----------------------------------------\n" + "Reduce file count: %s\n" + "Reduce file size: %s\n" + "-----------------------------------------", - timeClock.getCoast(), + timeClock.getCost(), mergeDuplicatedTotalCount, getNetFileSizeDescription(mergeDuplicatedTotalSize) )); diff --git a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java index c21b0bf..046e238 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/executors/ResourcesObfuscator.java @@ -39,9 +39,6 @@ import java.util.stream.Stream; import java.util.zip.ZipFile; -import groovy.util.logging.Log; - -import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist; import static com.bytedance.android.aabresguard.bundle.AppBundleUtils.getEntryNameByResourceName; import static com.bytedance.android.aabresguard.bundle.AppBundleUtils.getTypeNameByResourceName; import static com.bytedance.android.aabresguard.bundle.ResourcesTableOperation.checkConfiguration; @@ -115,8 +112,8 @@ public AppBundle obfuscate() throws IOException { .build(); System.out.println(String.format( - "obfuscate resources done, coast %s", - timeClock.getCoast() + "obfuscate resources done, cost %s", + timeClock.getCost() )); // write mapping rules to file. @@ -182,23 +179,25 @@ private void generateResourceMappingRule(BundleModule bundleModule, Map obfuscateModuleEntries(BundleModule bundleModule, Ma String bundleRawPath = bundleModule.getName().getName() + "/" + entry.getPath().toString(); String bundleObfuscatedPath = resourcesMapping.getEntryFilesMapping().get(bundleRawPath); if (bundleObfuscatedPath == null) { + //System.out.println(": "+bundleRawPath); if (!shouldBeObfuscated(bundleRawPath)) { System.out.println(String.format( "[whiteList] find whiteList resource file, resource: %s", @@ -245,6 +245,7 @@ private Map obfuscateModuleEntries(BundleModule bundleModule, Ma String obfuscatedName = guardStringBuilder.getReplaceString(mapping); mapping.add(obfuscatedName); bundleObfuscatedPath = obfuscateDir + "/" + obfuscatedName + fileSuffix; + //System.out.println(" -> "+bundleObfuscatedPath); resourcesMapping.putEntryFileMapping(bundleRawPath, bundleObfuscatedPath); } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java b/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java index b77c859..dc82c85 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/utils/TimeClock.java @@ -12,7 +12,7 @@ public TimeClock() { startTime = System.currentTimeMillis(); } - public String getCoast() { + public String getCost() { return (System.currentTimeMillis() - startTime) + ""; } } diff --git a/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java b/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java index a621b50..2490571 100644 --- a/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java +++ b/core/src/test/java/com/bytedance/android/aabresguard/utils/FileOperationTest.java @@ -23,7 +23,7 @@ public void testUnZip() throws IOException { Path unzipDirPath = getTempDirPath(); Path targetDir = new File(getTempDirPath().toFile(), "/aab").toPath(); FileOperation.uncompress(aabFile.toPath(), targetDir); - System.out.println("testUnZip method coast:"); + System.out.println("testUnZip method cost:"); FileOperation.uncompress(aabFile.toPath(), unzipDirPath); } diff --git a/wiki/en/DATA.md b/wiki/en/DATA.md index d782cc2..71c5bc0 100644 --- a/wiki/en/DATA.md +++ b/wiki/en/DATA.md @@ -12,7 +12,7 @@ The current data of size savings for multiple products is below: **AabResGuard-0.1.0** -|App|coast time|aab size|apk raw size|apk download size| +|App|cost time|aab size|apk raw size|apk download size| |---|-------|--------|-------------|----------------| |Tiktok/840|75s|-2.9MB|-1.9MB|-0.7MB| |Vigo/v751|60s|-1.0Mb|-1.4MB|-0.6MB| From de51513c53ed817b46f1dcaee4da62b32aa190d8 Mon Sep 17 00:00:00 2001 From: Martin Loren <37680207+martinloren@users.noreply.github.com> Date: Fri, 15 Oct 2021 10:00:44 +0800 Subject: [PATCH 14/17] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 863fc8c..2b0c52f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# AabResGuard - MartinLoren Edition +# AabResGuard - Artic Fox Edition

The tool of obfuscated aab resources

@@ -6,14 +6,13 @@ [Download V.0.1.10](https://github.com/martinloren/mvn-repo/raw/main/AabResGuard_0.1.10.zip) -[![License](https://img.shields.io/badge/license-Apache2.0-brightgreen)](LICENSE) -[![Bundletool](https://img.shields.io/badge/Dependency-Bundletool/0.10.0-blue)](https://github.com/google/bundletool) +[![License](https://img.shields.io/badge/license-Apache2.0-brightgreen)](LICENSE) [![Bundletool](https://img.shields.io/badge/Dependency-Bundletool/0.10.0-blue)](https://github.com/google/bundletool) **[English](README.md)** | [简体中文](wiki/zh-cn/README.md) > Powered by bytedance douyin android team. -## Features$$ +## Features > The tool of obfuscated aab resources. - **Merge duplicated resources:** Consolidate duplicate resource files to reduce package size. @@ -120,6 +119,7 @@ Read the details to learn how to participate in the improvement **AabResGuard**. * [Zilai Jiang](https://github.com/Zzzia) * [Zhiqian Yang](https://github.com/yangzhiqian) * [Xiaoshuang Bai (Designer)](https://www.behance.net/shawnpai) +* [Martinloren](https://github.com/martinloren) ## Thanks * [AndResGuard](https://github.com/shwenzhang/AndResGuard/) From 360c2ed7882eeee7826689e0ac25e6529e2b6926 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 11 Nov 2021 21:27:19 +0100 Subject: [PATCH 15/17] remove reference to jcenter repo which was shutdown --- README.md | 7 +++---- build.gradle | 2 -- core/build.gradle | 1 - wiki/zh-cn/README.md | 1 - 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2b0c52f..cc15469 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ - **???:** Looking ahead, there will be more feature support, welcome to submit PR & issue. ## [Data of size savings](wiki/en/DATA.md) -**AabResGuard** is a resource obfuscation tool powered by the douyin Android team. It has been launched at the end of July 2018 in several overseas products, such as **Tiktok, Vigo**, etc. -There is no feedback on related resource issues. +**AabResGuard** is a resource obfuscation tool powered by the douyin Android team. It has been launched at the end of July 2018 in several overseas products, such as **Tiktok, Vigo**, etc. +There is no feedback on related resource issues. For more data details, please go to **[Data of size savings](wiki/en/DATA.md)**. ## Quick start @@ -38,7 +38,6 @@ buildscript { repositories { mavenCentral() mavenLocal() - jcenter() google() } dependencies { @@ -77,7 +76,7 @@ aabResGuard { "*/arm64-v8a/*", "META-INF/*" ] - + enableFilterStrings = false // switch of filter strings unusedStringPath = file("unused.txt").toPath() // strings will be filtered in this file languageWhiteList = ["en", "zh"] // keep en,en-xx,zh,zh-xx etc. remove others. diff --git a/build.gradle b/build.gradle index 0f43f54..2749954 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,6 @@ buildscript { apply from: rootProject.file("gradle/config.gradle") repositories { google() - //jcenter() if ("true".equalsIgnoreCase(System.getProperty('useLocalMaven', "false"))) { println "Using local repo." mavenLocal() @@ -33,7 +32,6 @@ buildscript { allprojects { repositories { google() - jcenter() if ("true".equalsIgnoreCase(System.getProperty('useLocalMaven', "false"))) { mavenLocal() } else { diff --git a/core/build.gradle b/core/build.gradle index 7edac6b..fda1b84 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,6 +1,5 @@ buildscript { repositories { - jcenter() maven { url "https://plugins.gradle.org/m2/" } diff --git a/wiki/zh-cn/README.md b/wiki/zh-cn/README.md index f057cfb..160ab78 100644 --- a/wiki/zh-cn/README.md +++ b/wiki/zh-cn/README.md @@ -36,7 +36,6 @@ buildscript { repositories { mavenCentral() - jcenter() google() } dependencies { From 737eb4c33b14e468eaa55638e1b1e9ff2c94d4c1 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 11 Nov 2021 21:31:41 +0100 Subject: [PATCH 16/17] Ignore lines not starting with white space when parsing --- .../android/aabresguard/parser/ResourcesMappingParser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java b/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java index d8758bf..9dfdd4a 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/parser/ResourcesMappingParser.java @@ -16,8 +16,8 @@ * Email: yangjing.yeoh@bytedance.com */ public class ResourcesMappingParser { - private static final Pattern MAP_DIR_PATTERN = Pattern.compile("\\s+(.*)->(.*)"); - private static final Pattern MAP_RES_PATTERN = Pattern.compile("\\s+(.*):(.*)->(.*)"); + private static final Pattern MAP_DIR_PATTERN = Pattern.compile("^\\s+(.*)->(.*)"); + private static final Pattern MAP_RES_PATTERN = Pattern.compile("^\\s+(.*):(.*)->(.*)"); private final Path mappingPath; public ResourcesMappingParser(Path mappingPath) { From 94781233eefb7ce07431f22007d9b7744ea42e8a Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 11 Nov 2021 22:31:11 +0100 Subject: [PATCH 17/17] add github actions build --- .github/workflows/build.yml | 66 +++++++++++++++++++++++++++++++++++++ README.md | 7 ++-- gradle.properties | 2 +- 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..604d0dd --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,66 @@ +# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions +name: Build + +on: + push: + branches: + - '**' + tags-ignore: + - '**' + pull_request: + workflow_dispatch: + # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/ + +defaults: + run: + shell: bash + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - name: Git Checkout + uses: actions/checkout@v2 #https://github.com/actions/checkout + + - name: Set up JDK 11 + uses: actions/setup-java@v2 # https://github.com/actions/setup-java + with: + distribution: 'zulu' + java-version: 11 + + - name: "Cache: Local Maven Repository" + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository + !~/.m2/com/bytedance + key: ${{ runner.os }}-mvnrepo-${{ hashFiles('**/build.gradle') }} + restore-keys: | + ${{ runner.os }}-mvnrepo- + + - name: Build with Gradle + run: | + set -eux + + bash ./gradlew publishToMavenLocal + + - name: Deploy Maven Repo + run: | + set -eux + + if git checkout --orphan mvn-repo; then + git rm -rf . + git clean -fxd + fi + + # https://github.community/t/github-actions-bot-email-address/17204 + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + mkdir -p com/bytedance/android + cp -rf ~/.m2/repository/com/bytedance/android/* com/bytedance/android + + git add --all + git commit -am "deploy to maven repo" + git push origin mvn-repo --force diff --git a/README.md b/README.md index 2b0c52f..8d7c637 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ - **???:** Looking ahead, there will be more feature support, welcome to submit PR & issue. ## [Data of size savings](wiki/en/DATA.md) -**AabResGuard** is a resource obfuscation tool powered by the douyin Android team. It has been launched at the end of July 2018 in several overseas products, such as **Tiktok, Vigo**, etc. -There is no feedback on related resource issues. +**AabResGuard** is a resource obfuscation tool powered by the douyin Android team. It has been launched at the end of July 2018 in several overseas products, such as **Tiktok, Vigo**, etc. +There is no feedback on related resource issues. For more data details, please go to **[Data of size savings](wiki/en/DATA.md)**. ## Quick start @@ -40,6 +40,7 @@ buildscript { mavenLocal() jcenter() google() + maven { url 'https://raw.githubusercontent.com/martinloren/AabResGuard/mvn-repo' } } dependencies { classpath "com.bytedance.android:aabresguard-plugin:0.1.10" @@ -77,7 +78,7 @@ aabResGuard { "*/arm64-v8a/*", "META-INF/*" ] - + enableFilterStrings = false // switch of filter strings unusedStringPath = file("unused.txt").toPath() // strings will be filtered in this file languageWhiteList = ["en", "zh"] // keep en,en-xx,zh,zh-xx etc. remove others. diff --git a/gradle.properties b/gradle.properties index a067f45..69c3687 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ PUBLISH_LOCAL_REPO=../repo useLocalMaven=true # 是否源码依赖 useSource=true -enableAabResGuardPlugin=true +enableAabResGuardPlugin=false # bintray uploadToBintray=false bintrayInfo.user=****