Android code obfuscation considerations

Source: Internet
Author: User

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 *
  
 


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.