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 bfab48d..4f7dccc 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# AabResGuard +# AabResGuard - Artic Fox 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/) -[![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) +[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) **[English](README.md)** | [简体中文](wiki/zh-cn/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 @@ -37,11 +37,12 @@ Configured in `build.gradle(root project)` buildscript { repositories { mavenCentral() - jcenter() + mavenLocal() google() + maven { url 'https://raw.githubusercontent.com/martinloren/AabResGuard/mvn-repo' } } dependencies { - classpath "com.bytedance.android:aabresguard-plugin:0.1.0" + classpath "com.bytedance.android:aabresguard-plugin:0.1.10" } } ``` @@ -50,10 +51,24 @@ 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" + "*.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 @@ -62,7 +77,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. @@ -104,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/) diff --git a/build.gradle b/build.gradle index 8762284..2749954 100644 --- a/build.gradle +++ b/build.gradle @@ -4,12 +4,11 @@ buildscript { apply from: rootProject.file("gradle/config.gradle") repositories { google() - 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") } } @@ -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 ce3725e..fda1b84 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,12 +1,11 @@ buildscript { repositories { - jcenter() maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.8" + classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.13" } } @@ -30,24 +29,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/gitignore b/core/gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/core/gitignore @@ -0,0 +1 @@ +/build 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 ba2fa55..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 @@ -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; @@ -72,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) )); @@ -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..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 @@ -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,7 +39,6 @@ import java.util.stream.Stream; import java.util.zip.ZipFile; -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; @@ -71,7 +72,11 @@ public ResourcesObfuscator(Path bundlePath, AppBundle rawAppBundle, Set