Android Code obfuscation considerations

Source: Internet
Author: User

There are a lot of problems with Android code confusion, here are a few things to note 1. The jar Baujo used in the dependent project is the same as the jar package in the project itself, and the same jar package can be removed directly from the dependent project. 2.native method to block obfuscation example: # Natvie method does not confuse-keepclasseswithmembernames class * {native <methods>;} 3. If there is a custom base class activity in which the control injects values by name, the following method is used to prevent the field from being mixed as the base class activity has the following control injection method protected void Smartinject () {class<? exte           NDS activity> Clz=getclass ();          Field[] Fs=clz.getdeclaredfields ();          Resources res = getresources ();          String PackageName = Getpackagename (); for (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 App package name.  r$id{*;} -keep public class * extends package name. base class Activity {<fields>;} 3. Common some code to prevent the confusion of the wording-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*


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Code obfuscation considerations

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.