混淆后,如果要查看混淆效果,有两种方式:
一、反编译dex或者jar文件,如果要查看so,可以objdump -tT libblecipher.so
二、查看混淆输出文件:
dump.txt 描述.apk文件中所有类文件间的内部结构
mapping.txt 列出了原始的类,方法和字段名与混淆后代码间的映射。
seeds.txt 列出了未被混淆的类和成员
usage.txt 列出了从.apk中删除的代码
有时候proguard会自动删除无用类,但是作为library module,proguard无法知晓有人调用,所以会错删,用-dontshrink 来禁止这种情况。
最好带上
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,Annotation,EnclosingMethod
尤其是Signature和InnerClasses,否则会出现一些奇怪的问题。
我遇到的混淆问题是接口开放,所以不能混淆,而实现需要混淆,这里可以给实现类中所有public的函数全部keep住,包括内部类。如下:
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class com.xiaomi.smarthome.bluetooth.security.BLECipher {
public <methods>;
}
-keep class com.dingjikerbo.bluetooth.library.BluetoothManager {
*;
}
-keep class com.dingjikerbo.bluetooth.library.BluetoothManager$* {
*;
}
-keep class com.dingjikerbo.bluetooth.library.response.BleResponse {
<methods>;
}
-keep interface * extends com.dingjikerbo.bluetooth.library.response.BleResponse
这里BleResponse是接口,而BluetoothManager实现了这个接口,不过只是一层壳而已,真正的实现需要调用其它的类,如果BluetoothManager混淆了,那么接口就找不到函数了,所以BluetoothManager不能混淆,而BluetoothManager调用的别的类是可以混淆的。
可以某些module混淆,某些module不混淆,都在build.gradle中设置