AndResGuard瘦身APK

    xiaoxiao2021-03-25  98

    AndResGuard是一个帮助你缩小APK大小的工具,他的原理类似Java Proguard,但是只针对资源。他会将原本冗长的资源路径变短,例如将res/drawable/wechat变为r/d/a。

    AndResGuard不涉及编译过程,只需输入一个apk(无论签名与否,debug版,release版均可,在处理过程中会直接将原签名删除),可得到一个实现资源混淆后的apk(若在配置文件中输入签名信息,可自动重签名并对齐,得到可直接发布的apk)以及对应资源ID的mapping文件。

    项目地址: https://github.com/shwenzhang/AndResGuard

    Gradle集成

    Project/build.gradle buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.1.14'

    } }

    Module/build.gradle

    apply plugin: 'com.android.application' apply plugin: 'AndResGuard' android { ... } dependencies { ... } andResGuard { // mappingFile = file("./resource_mapping.txt") mappingFile = null use7zip = true useSign = true // 打开这个开关,会keep住所有资源的原始路径,只混淆资源的名字 keepRoot = false whiteList = [ // for your icon "R.drawable.icon" ] compressFilePattern = [ "*.png", "*.jpg", "*.jpeg", "resources.arsc" ] sevenzip { artifact = 'com.tencent.mm:SevenZip:1.1.14' //path = "/usr/local/bin/7za" --- Linux //path = "D:\7za\7za.exe" --- Windows } }

    如何使用

    在Android Gradle Terminal中

    Windows

    gradlew.bat resguardRelsese

    OS X or Linux

    ./gradlew reguardRelease

    注意问题

    mappingFile用于增量更新,保持本次混淆与上次混淆结果一致; uss7zip为true时,useSign必须为true; useSign为true时,需要配置signConfig; whiteList添加在代码内部需要动态获取的资源id; sevenzip可使用artifacr或path,path指本地安装的7za(7zip命令行工具)。

    转载请注明原文地址: https://ju.6miu.com/read-12652.html

    最新回复(0)