android resolves conflicts between code obfuscation and reflection

Source: Internet
Author: User

The previous code is confusing because it doesn't use reflection, so the usual code obfuscation can pass through, and some classes in this project use the reflection mechanism (I have instant messaging in this project, so there is an emoticon resource, so we need to find the expression resource ID by reflection by the file name). When the file name to find the resource ID when the null pointer exception, the beginning of the period I do not know what the reason, by anti-compilation has been confused apk, step by step to find the wrong place, only to realize that the reflection that step appeared the problem: Field field = R.drawable.class.getdeclaredfield (name); Go to this step and hang up, the program crashes directly.

Workaround :

1. In the proguard.cfg file, the variables in the class to which the reflection is used are not confused:

such as:-keep public class Com.byl.bean.Expressions {*;}, indicating that all variables and methods in Expressions class and class are not confused, note that the full path is to be written;

2. Filter generics: -keepattributes Signature

3. The most important point: keep R files from being confused, otherwise, your reflection is not getting the resource ID:-keep class * *. r$* {*;}


Next, let's talk about the method steps of anti-compilation:

1. Download the Anti-compilation tool: dex2jar:http://download.csdn.net/detail/baiyuliang2013/7801333

2. After decompression


3. Replace the APK installation package you have confused with. apk to. zip;

4. Unzip the. zip and extract the Classes.dex files into the Dex2jar folder.


5. Bring up the cmd command and navigate to the Dex2jar folder location,


6. After positioning, enter in cmd: Dex2jar.bat classes.dex, then press ENTER,


7. Now your Dex2jar folder will generate a file named: Classes.dex.dex2jar.jar, open the jar with Jd-gui to see the confusing source,jd-gui:http:// download.csdn.net/detail/baiyuliang2013/7801379

android resolves conflicts between code obfuscation and reflection

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.