Web Analytics

ResChiper

⭐ 106 stars Simplified Chinese by goldfish07

ResChiper

failed to load artifacts/logo.png

AAB 资源混淆工具

License Android Gradle Plugin BundleTool JDK Version Gradle Version ResChiper Version

目录

介绍

ResChiper 是一款用于混淆 Android AAB 资源的工具。 它可以保护您的资源免受未经授权的访问,并减少您的应用 AAB 大小。

快速开始

按照以下步骤将 AAB 资源混淆工具集成到您的 Android 项目中:

要求

在开始使用 ResChiper 之前,请确保您的应用满足以下要求:

安装

#### 1. 添加 ResChiper Gradle 插件

在您项目根目录下的 build.gradle 文件中,添加 ResChiper Gradle 插件到 buildscript 部分:

buildscript {
  dependencies {
    classpath "io.github.goldfish07.reschiper:plugin:"
  }
  
  repositories {
    mavenCentral()
    google()
   }
}

#### 2. 应用插件

在你的应用级 build.gradle 文件中,应用 ResChiper 插件:

apply plugin: "io.github.goldfish07.reschiper"

#### 3. 配置插件

在你的 app/build.gradle 文件中,通过指定所需的设置来配置 ResChiper 插件。以下是一个示例 配置:

resChiper {
    enableObfuscation = true //by default res obfuscate is enabled
    obfuscationMode = "default" //["dir", "file", "default"]
    obfuscatedBundleName = "reschiper-app.aab" // Obfuscated file name, must end with '.aab'
    //mappingFile = file("path/to/your/mapping.txt").toPath() // Mapping file used for incremental obfuscation
    whiteList = [
                  //Whitelist rule (directory name to exclude)
                  "res/raw", // raw dir will not be obfuscated
                  "res/xml", // xml dir will not be obfuscated

//Whitelist rule (file name to exclude) "res/raw/*", // all files inside raw directory will not be obfuscated "res/raw/success_tick.json", // success_tick.json file will not be obfuscated "res/xml/*", // all files inside xml directory will not be obfuscated

// White list rules (resource name to exclude) ".R.raw.", ".R.xml.",

// for google-services "*.R.string.google_api_key", "*.R.string.google_app_id", "*.R.string.default_web_client_id", "*.R.string.gcm_defaultSenderId", "*.R.string.ga_trackingId", "*.R.string.firebase_database_url", "*.R.string.google_crash_reporting_api_key", "*.R.string.google_storage_bucket", "*.R.integer.google_play_services_version", //firebase "*.R.string.project_id", //firebase crashlytics "*.R.string.com.google.firebase.crashlytics.mapping_file_id", "*.R.bool.com.crashlytics.useFirebaseAppId", "*.R.string.com.crashlytics.useFirebaseAppId", "*.R.string.google_app_id", "*.R.bool.com.crashlytics.CollectDeviceIdentifiers", "*.R.string.com.crashlytics.CollectDeviceIdentifiers", "*.R.bool.com.crashlytics.CollectUserIdentifiers", "*.R.string.com.crashlytics.CollectUserIdentifiers", "*.R.string.com.crashlytics.ApiEndpoint", "*.R.string.com.crashlytics.android.build_id", "*.R.bool.com.crashlytics.RequireBuildId", "*.R.string.com.crashlytics.RequireBuildId", "*.R.bool.com.crashlytics.CollectCustomLogs", "*.R.string.com.crashlytics.CollectCustomLogs", "*.R.bool.com.crashlytics.Trace", "*.R.string.com.crashlytics.Trace", "*.R.string.com.crashlytics.CollectCustomKeys" ] mergeDuplicateResources = true // allow the merge of duplicate resources enableFileFiltering = true enableFilterStrings = true fileFilterList = [ // file filter rules "META-INF/*", // "/armeabi-v7a/", // "/arm64-v8a/", // "/x86/", // "/x86_64/" ] unusedStringFile = "path/to/your/unused_strings.txt" // strings will be filtered in this file localeWhiteList = ["en", "in", "fr"] //keep en,en-xx,in,in-xx,fr,fr-xx and remove others locale. }

使用方法

要混淆您的资源并生成混淆的 AAB,请在项目根目录下运行以下 Gradle 命令。:

./gradle clean :app:resChiperDebug --stacktrace
此命令将在项目根目录执行混淆过程,混淆后的 AAB 将生成在 app/build/outputs/bundle/debug 目录中。

配置选项

ResChiper 扩展提供了各种资源混淆的配置选项,包括启用/禁用混淆、指定映射文件、资源白名单等。

示例

你可以在这里查看一些配置示例。

白名单

构建过程中不进行混淆的资源。
你可以在这里找到 whiteList 配置。

输出

运行混淆过程后,你可以获得以下输出文件:

不同构建之间的一致性。 运行 ResChiper 工具后,将生成这些输出文件,您可以在项目构建输出的相关目录中找到它们。

致谢

ResChiper 灵感来源于以下项目和工具:

许可证

Apache License v2.0 logo

版权所有 (C) 2023 goldfish07 (Ayush Bisht) 本文件是 ResChiper 的一部分。

ResChiper 是自由软件:您可以在 Apache 软件基金会发布的 Apache 许可证版本 2.0 条款下重新分发和/或修改它, 许可证版本为 2.0 或(由您选择)任何更高版本。

根据 Apache 许可证版本 2.0(“许可证”)授权; 除非符合许可证要求,否则您不得使用此文件。 您可以从以下地址获取许可证副本:

http://www.apache.org/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则根据许可证分发的软件按“原样”提供, 不附带任何明示或暗示的保证或条件。 有关权限和限制的具体条款,请参阅许可证。

--- Tranlated By Open Ai Tx | Last indexed: 2026-06-02 ---