Andresguard的技术原理,推荐大家阅读原作者的博文: 安装包立减1M--微信Android资源混淆打包工具



apply plugin: 'AndResGuard'

buildscript {
    repositories {
    dependencies {
        classpath ''

andResGuard {
    // mappingFile = file("./resource_mapping.txt")
    mappingFile = null
    use7zip = true
    useSign = true
    // 打开这个开关,会keep住所有资源的原始路径,只混淆资源的名字
    keepRoot = false
    whiteList = [
        // for your icon
        // for fabric
        // for google-services
    compressFilePattern = [
    sevenzip {
         artifact = ''
         //path = "/usr/local/bin/7za"

    * 可选: 如果不设置则会默认覆盖assemble输出的apk
    // finalApkBackupPath = "${project.rootDir}/final.apk"

    * 可选: 指定v1签名时生成jar文件的摘要算法
    * 默认值为“SHA-1”
    // digestalg = "SHA-256"



  • 如果不是对APK size有极致的需求,请不要把resource.asrc添加进compressFilePattern. (#84 #233)
  • 对于发布于Google Play的APP,建议不要使用7Zip压缩,因为这个会导致Google Play的优化Patch算法失效. (#233)


I like the idea of having a toolbox that lets you further optimize your APK, but some of the "optimizations" offered by AndResGuard go against good practices:

there are good reasons why some files in the APK are not compressed, such as resources.arsc or native libraries (*.so/dll), so they can be read directly from APK at runtime. By offering/suggesting adding compression to them you in fact prevent optimization and degrade the experience at runtime. Ideally AndResGuard should not compress resources.arsc or at least add an explanation in the manual of why it's not a good idea.

recompressing the APK with 7zip makes little sense for APKs distributed via Play, as it might prevent some optimizations such as File-by-file patches, which greatly reduce download size for updates. Also the initial download from Play is compressed anyway, so this andresguard feature would only affect the APK size on disk and to a small degree. At the very least you shouldn't guide developers who distribute on Play to use 7zip recompression


powered by Gitbook更新: 2018-04-17

results matching ""

    No results matching ""