android代码混淆aar,如何使用Proguard混淆android库(.aar)?

I want to obfuscate the .aar library using proguard for distribution purpose, I tried many solution over internet but nothing has worked till now, only some code are obfuscated. Can anybody help me to solve the issue?

解决方案

In your build.gradle, add consumerProguardFiles under defaultConfig :

android {

compileSdkVersion Integer.parseInt("${COMPILE_SDK}")

buildToolsVersion "${BUILD_TOOLS_VERSION}"

defaultConfig {

targetSdkVersion Integer.parseInt("${TARGET_SDK}")

minSdkVersion Integer.parseInt("${MIN_SDK}")

consumerProguardFiles 'consumer-proguard-rules.pro'

}

}

You add a file named consumer-proguard-rules.pro under the root folder of your library project. This file should contain all the proguard rules of the dependencies mentioned in the build.gradle of your library project. You should add a keep rule for your POJO classes, interfaces with annotations and whatever other class that you need to be kept safe from proguard cleaning or obfuscation.

If you shrink resources, you should add a keep.xml file in your resources under res (res/raw for example). In this file you specify the drawables or layouts to keep. You check in your code in you use reflexion to call a resource with getResources().getIdentifier(..), if so you add your drawables like this.

xmlns:tools="http://schemas.android.com/tools"

tools:shrinkMode="safe"

tools:keep="@layout/layout1, @drawable/icon1,@drawable/icon2,@drawable/img_*"/>

You can use * to tell proguard to keep all the drawables that start with img_ under the drawable folder.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值