gitmyhub

AndResGuard

Java ★ 8.6k updated 2y ago

proguard resource for Android by wechat team

An Android Gradle plugin from the WeChat team that shrinks APK file sizes by renaming resource files to very short paths and recompressing with 7zip, while also making assets harder to reverse-engineer.

JavaGradleAndroid7zipsetup: moderatecomplexity 3/5

AndResGuard is a tool that shrinks the file size of Android app packages. It was created by the WeChat team at Tencent. The basic idea is similar to what ProGuard does for Java source code, except this tool targets resource files instead. ProGuard renames Java classes to shorter names to reduce file size and make the code harder to reverse-engineer; AndResGuard does the same thing for images, layouts, strings, and other assets inside the app package.

In practice, the tool takes a finished Android app file (an APK) as input, renames its internal resource folders and files to very short names, and then repackages everything using 7zip compression. For example, a file at the path res/drawable/wechat.png might become r/d/a.png. These short names mean less data in the package index, and combined with stronger 7zip compression the result is a noticeably smaller download for users.

The tool serves two related purposes. First, it obfuscates the app's resources, which makes it harder for someone using a tool like Apktool to inspect and copy the app's assets. Second, it reduces the package size, which matters for app stores and user data costs. Both effects come from the same renaming-and-recompressing pass.

Developers add AndResGuard to an Android project as a Gradle plugin, which is the standard way to hook into Android's build process. The configuration block lets you specify a white list of resource names to leave unchanged (for resources accessed by string name at runtime, which would break if renamed), set compression levels per file type, choose whether to use 7zip, and optionally provide a mapping file to keep specific folder paths intact.

A few practical notes from the README: avoid adding the main resource table file to the compression list unless app size is a top priority, and avoid enabling 7zip when distributing through Google Play, since Google Play uses a file-level patching system for updates that does not work well with 7zip-compressed packages.

Where it fits