Android code obfuscation considerations
Android code obfuscation often causes various problems. The following lists some precautions. if the jar package used in the dependent project is the same as the jar package in the project itself, delete the same jar package in the dependent project. native method to prevent obfuscation example: # The natvie method is not Obfuscated-keepclasseswithmembernames class * {native
;} 3. if the custom base Class Activity contains injection values based on the control name, use the following method to prevent the field from being mixed. For example, the following control injection method is available in the base Class Activity: protected void smartInject () {Class
Clz = getClass (); Field [] fs = clz. getDeclaredFields (); Resources res = getResources (); String packageName = getPackageName (); for (Field field Field: fs) {if (! View. class. isAssignableFrom (field. getType () {continue;} int viewId = res. getIdentifier (field. getName (), id, packageName); if (viewId = 0) continue; field. setAccessible (true); try {View v = findViewById (viewId); field. set (this, v); Class
C = field. getType (); Method m = c. getMethod (setOnClickListener, android. view. view. onClickListener. class); m. invoke (v, this);} catch (Throwable e) {// e. printStackTrace ();} field. setAccessible (false) ;}}-keep class application package name. r$ id {*;}-keep public class * extends package name. base Activity {
;} 3. some common methods to prevent code obfuscation-keep class com. iflytek. ** {*;}-libraryjars libs/BaiduLBS_Android.jar-libraryjars libs/fastjson-1.1.39.jar-libraryjars libs/bcprov-jdk15-143.jar-libraryjars libs/android-support-v4.jar-keep class com. baidu. ** {*;}-keep class vi.com. gdi. bgl. android. ** {*;}-keep class okio. ** {*;}-dontwarn okio. **-dontwarn com. alibaba. **-dontwarn org. bouncycastle. **-keepattributes Signature-keepattributes * Annotation *