Top Related Projects
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
ProGuard, Java optimizer and obfuscator
A powerful Android Dynamic Component Framework.
提高 Android UI 开发效率的 UI 库
Quick Overview
AndResGuard is an Android resource obfuscator that aims to reduce the size of Android APK files by obfuscating the resource names. It is a command-line tool that can be integrated into the Android build process to automatically obfuscate the resources during the build.
Pros
- Reduced APK Size: AndResGuard can significantly reduce the size of the final APK file by obfuscating the resource names, which can be especially beneficial for large Android applications.
- Improved Security: Obfuscating the resource names can make it more difficult for attackers to reverse-engineer and understand the application's structure and functionality.
- Customizable Obfuscation: AndResGuard provides a range of configuration options to customize the obfuscation process, allowing developers to balance the trade-off between file size reduction and maintainability.
- Compatibility: The tool is designed to be compatible with a wide range of Android build tools and can be easily integrated into existing build processes.
Cons
- Increased Build Time: The obfuscation process can add some overhead to the build process, which may be a concern for projects with tight build time constraints.
- Potential Compatibility Issues: While AndResGuard is designed to be compatible with most Android projects, there may be cases where the obfuscation process can cause issues with certain libraries or frameworks.
- Reduced Readability: The obfuscated resource names can make the application's code and resources more difficult to understand and maintain, which may be a concern for larger projects or teams.
- Limited Documentation: The project's documentation, while generally helpful, could be more comprehensive and provide more detailed guidance for users.
Code Examples
Not applicable, as AndResGuard is a command-line tool and not a code library.
Getting Started
To get started with AndResGuard, follow these steps:
- Download the latest release of AndResGuard from the GitHub repository.
- Extract the downloaded archive and navigate to the
bin
directory. - Run the
andresguard
command with the appropriate arguments to obfuscate your Android project's resources. For example:
./andresguard -config config.xml -out obfuscated.apk -apk your-app.apk
The config.xml
file is used to configure the obfuscation process. Here's an example configuration:
<?xml version="1.0" encoding="UTF-8"?>
<resproguard>
<mapping>mapping.txt</mapping>
<sevenzip>7za</sevenzip>
<whitelist>
<item>R.string</item>
<item>R.drawable</item>
<item>R.color</item>
</whitelist>
<keeproot>true</keeproot>
<keepattributes>true</keepattributes>
<keepclassattributes>true</keepclassattributes>
<keepnames>
<item>com.your.package.MainActivity</item>
</keepnames>
<dontwarn>
<item>com.google.android.gms.**</item>
</dontwarn>
</resproguard>
This configuration file specifies the mapping file to be generated, the 7-Zip executable to use, a whitelist of resources to keep unobfuscated, and various other options to customize the obfuscation process.
For more detailed information on the configuration options and usage of AndResGuard, please refer to the project's README and Wiki pages.
Competitor Comparisons
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
Pros of Tinker
- Tinker provides a hot-fix solution for Android apps, allowing developers to quickly patch and deploy updates without the need for a full app update.
- Tinker supports multiple Android platforms, including Dalvik and ART, making it a versatile solution.
- Tinker's integration with the build process is seamless, making it easy to set up and use in existing projects.
Cons of Tinker
- Tinker's hot-fix solution may not be suitable for all types of app updates, as it has limitations in terms of the types of changes it can handle.
- Tinker's documentation and community support may not be as extensive as some other Android tools.
- Tinker's performance impact on the app may be a concern for some developers, as it adds additional processing overhead.
Code Comparison
AndResGuard:
public class AndResGuard {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: java -jar AndResGuard.jar <input_apk_path> [<output_apk_path>]");
return;
}
String inputApkPath = args[0];
String outputApkPath = args.length > 1 ? args[1] : inputApkPath;
AndResGuardCore.doAndResGuard(inputApkPath, outputApkPath);
}
}
Tinker:
public class TinkerPatchService extends IntentService {
public static void runPatchService(Context context, Intent intent) {
Intent runIntent = new Intent(context, TinkerPatchService.class);
runIntent.putExtras(intent);
context.startService(runIntent);
}
@Override
protected void onHandleIntent(Intent intent) {
TinkerPatchExecutor.getInstance().executePatch(this, intent);
}
}
ProGuard, Java optimizer and obfuscator
Pros of ProGuard
- ProGuard is a widely-used and well-established code obfuscation tool, with a large user community and extensive documentation.
- It supports a wide range of configuration options, allowing for fine-grained control over the obfuscation process.
- ProGuard is actively maintained and regularly updated, ensuring compatibility with the latest Android versions and tools.
Cons of ProGuard
- ProGuard can be more complex to configure and use compared to AndResGuard, especially for larger projects with more complex dependencies.
- The obfuscation process can sometimes introduce unexpected issues or side effects, which may require additional troubleshooting.
- ProGuard's focus is primarily on code obfuscation, while AndResGuard specializes in resource obfuscation, which may be a more important concern for some projects.
Code Comparison
ProGuard configuration:
-keep class com.example.myapp.** { *; }
-keepclassmembers class com.example.myapp.** { *; }
-keepnames class com.example.myapp.** { *; }
-dontwarn com.example.myapp.**
-optimizationpasses 5
AndResGuard configuration:
{
"whiteList": [
"R.string",
"R.drawable",
"R.color"
],
"compressFilePattern": [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif"
],
"sevenZipLevel": 5
}
A powerful Android Dynamic Component Framework.
Pros of Atlas
- Atlas provides a modular architecture, allowing developers to split their app into smaller, independent modules.
- Atlas supports dynamic loading of modules, enabling on-demand loading of app components.
- Atlas offers a rich set of features, including hot-swapping, multi-dex support, and seamless integration with Android Studio.
Cons of Atlas
- Atlas has a steeper learning curve compared to AndResGuard, as it introduces a new modular architecture.
- The documentation for Atlas may not be as comprehensive as that of AndResGuard, making it more challenging for newcomers to get started.
- Atlas may have a larger impact on app size and performance due to its modular nature, which could be a concern for some developers.
Code Comparison
AndResGuard:
public class AndResGuard {
public static void main(String[] args) {
// Parse command line arguments
CommandLine cmd = new CommandLine(new AndResGuardConfig());
try {
cmd.parseWithHandlers(new RunLast(), new DefaultExceptionHandler<>(), args);
// Perform resource obfuscation
AndResGuardCore.start(cmd.getParseResult().get(AndResGuardConfig.class));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Atlas:
public class AtlasInitializer {
public static void init(Application application) {
// Initialize Atlas
Atlas.getInstance().init(application);
// Register modules
Atlas.getInstance().registerBundleInfo(new BundleInfo("com.taobao.android.demo", "1.0.0"));
// Enable hot-swap
Atlas.getInstance().enableHotswap();
}
}
提高 Android UI 开发效率的 UI 库
Pros of QMUI_Android
- Provides a comprehensive UI framework with a wide range of pre-built components and utilities, making it easier to develop consistent and visually appealing Android applications.
- Includes a powerful theme management system, allowing developers to easily customize the appearance of their app.
- Offers a set of high-quality UI components, such as buttons, dialogs, and navigation bars, that are well-designed and highly customizable.
Cons of QMUI_Android
- The library may be considered overkill for smaller projects that don't require the full range of features and components provided by QMUI_Android.
- The learning curve for the library can be steeper compared to using more lightweight UI frameworks or building custom UI components from scratch.
- The library's dependency on the Android Support Library (now AndroidX) may limit its compatibility with older Android versions.
Code Comparison
QMUI_Android:
QMUIBottomSheet.BottomSheetBuilder builder = new QMUIBottomSheet.BottomSheetBuilder(this)
.addItem(R.drawable.icon_camera, "Take Photo")
.addItem(R.drawable.icon_album, "Choose from Album")
.setOnSheetItemClickListener(new QMUIBottomSheet.BottomSheetItemClickListener() {
@Override
public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
dialog.dismiss();
// handle click event
}
});
builder.build().show();
AndResGuard:
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: java -jar AndResGuard.jar <input_apk_path> [<output_apk_path>]");
return;
}
String inputApkPath = args[0];
String outputApkPath = args.length > 1 ? args[1] : inputApkPath;
AndResGuard.doGuard(inputApkPath, outputApkPath);
}
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
AndResGuard
Read this in other languages: English, ç®ä½ä¸æ.
AndResGuard
is a tooling for reducing your apk size, it works like the ProGuard
for Java source code, but only aim at the resource files. It changes res/drawable/wechat
to r/d/a
, and renames the resource file wechat.png
to a.png
. Finally, it repackages the apk with 7zip, which can reduce the package size obviously.
AndResGuard
is fast, and it does NOT need the source codes. Input an Android apk, then we can get a 'ResGuard' apk in a few seconds.
Some uses of AndResGuard
are:
-
Obfuscate android resources. It contains all the resource type(such as drawableãlayoutãstring...). It can prevent your apk from being reversed by
Apktool
. -
Shrinking the apk size. It can reduce the
resources.arsc
and the package size obviously. -
Repackage with
7zip
. It supports repackage apk with7zip
, and we can specify the compression method for each file.
AndResGuard
is a command-line tool, it supports Windows, Linux and Mac. We suggest you to use 7zip in Linux or Mac platform for a higher compression ratio.
How to use
With Gradle
This has been released on Bintray
apply plugin: 'AndResGuard'
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.21'
}
}
andResGuard {
// mappingFile = file("./resource_mapping.txt")
mappingFile = null
use7zip = true
useSign = true
// It will keep the origin path of your resources when it's true
keepRoot = false
// If set, name column in arsc those need to proguard will be kept to this value
fixedResName = "arg"
// It will merge the duplicated resources, but don't rely on this feature too much.
// it's always better to remove duplicated resource from repo
mergeDuplicatedRes = true
whiteList = [
// your icon
"R.drawable.icon",
// for fabric
"R.string.com.crashlytics.*",
// for google-services
"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.project_id",
]
compressFilePattern = [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
]
sevenzip {
artifact = 'com.tencent.mm:SevenZip:1.2.21'
//path = "/usr/local/bin/7za"
}
/**
* Optional: if finalApkBackupPath is null, AndResGuard will overwrite final apk
* to the path which assemble[Task] write to
**/
// finalApkBackupPath = "${project.rootDir}/final.apk"
/**
* Optional: Specifies the name of the message digest algorithm to user when digesting the entries of JAR file
* Only works in V1signing, default value is "SHA-1"
**/
// digestalg = "SHA-256"
}
Wildcard
The whiteList and compressFilePattern support wildcard include ? * +.
? Zero or one character
* Zero or more of character
+ One or more of character
WhiteList
You need put all resource which access via getIdentifier
into whiteList.
You can find more whitsList configs of third-part SDK in white_list.md. Welcome PR your configs which is not included in white_list.md
The whiteList only works on the specsName of resources, it wouldn't keep the path of resource.
If you wanna keeping the path, please use mappingFile
to implement it.
For example, we wanna keeping the path of icon, we need add below into our mappingFile
.
res path mapping:
res/mipmap-hdpi-v4 -> res/mipmap-hdpi-v4
res/mipmap-mdpi-v4 -> res/mipmap-mdpi-v4
res/mipmap-xhdpi-v4 -> res/mipmap-xhdpi-v4
res/mipmap-xxhdpi-v4 -> res/mipmap-xxhdpi-v4
res/mipmap-xxxhdpi-v4 -> res/mipmap-xxxhdpi-v4
How to Launch
If you are using Android Studio
, you can find the generate task option in andresguard
group.
Or alternatively, you run ./gradlew resguard[BuildType | Flavor]
in your terminal. The format of task name is as same as assemble
.
Sevenzip
The sevenzip
in gradle file can be set by path
or artifact
. Multiple assignments are allowed, but the winner is always path
.
Result
If finalApkBackupPath is null, AndResGuard will overwrite final APK to the path which assemble[Task] write. Otherwise, it will store in the path you assigned.
Other
Known Issue
- The first element of list which returned by
AssetManager#list(String path)
is empty string when you're using the APK which is compressed by 7zip. #162
Best Practise
- Do NOT add
resources.arsc
intocompressFilePattern
unless the app size is really matter to you.(#84 #233) - Do NOT enable 7zip compression(
use7zip
) when you distribute your APP on Google Play. It'll prevent the file-by-file patch when updating your APP. (#233)
Thanks
Apktool Connor Tumbleson
v2sig @jonyChina162
Top Related Projects
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
ProGuard, Java optimizer and obfuscator
A powerful Android Dynamic Component Framework.
提高 Android UI 开发效率的 UI 库
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot