Proguard-project.txtand project.propertiescoding code, proguardproject.txt

Source: Internet
Author: User

Proguard-project.txtand project.propertiescoding code, proguardproject.txt
[Switch] Use android proguard to confuse code to prevent decompilation and optimize code

Although there are many related blogs on the Internet, they do not seem to be the latest version .. So the open-source demo on Baidu + Google + github finally successfully configured android proguard.

The default configuration of the latest android sdk can meet most of our requirements. We only need to follow the sdk prompts to configure most of the required configurations, and then add some basic

You just need to customize the configuration.

  • Step 1: cancel the comments about proguard in project. properties. In this step, proguard can be enabled. Based on the blog on the Internet, it is best to add the sdk path.
sdk.dir=D:/Java/IDE/adt-bundle-windows-x86_64-20130219/sdkproguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

In this way, the default configuration file will also be included.

  • Step 2: Save the class called by AndroidManifest. xml or webview. This is because proguard will remove the code that is not called.
-keepclassmembersclass fqcn.of.javascript.interface.for.webview {   public *;}-keeppublic class *extends android.app.Activity                     -keeppublic class *extends android.app.Application                  -keeppublic class *extends android.app.Service                      -keeppublic class *extends android.content.BroadcastReceiver        -keeppublic class *extends android.content.ContentProvider          -keeppublic class *extends android.app.backup.BackupAgentHelper     -keeppublic class *extends android.preference.Preference  
  • Step 3: Third-party class libraries.
# Third-party class library-keepclass android. ** {*;}-keepclass com. jeremyfeinstein. slidingmenu. lib. ** {*;}-keepclass com. actionbarsherlock. ** {*;}-keepclass com. lidroid. xutils. **{*;}
  • Step 4: In fact, this step can replace all the above keep statements to minimize the probability of accidental deletion. That is, keep all classes with public access permissions and their public members.
-keepclasseswithmembersclass *{    public *;}
  • Step 5: Delete the Log code from the open-source proguarddemo on github.
-assumenosideeffectsclass android.util.Log {    public static *** e(...);    public static *** w(...);    public static *** wtf(...);    public static *** d(...);    public static *** v(...);}

Configure obfuscation and finally package the project:

Next, decompile the exported APK as follows:

 

It is found that in the generated jar file, all the class names and variable names are changed to a, B, c and other names that cannot be correctly understood, achieving the expected results.

 

[The above content has not been tested, and the content is from the network]

Reference address:

Http://blog.csdn.net/binyao02123202/article/details/18940715

Http://blog.csdn.net/pomme_qixiaohu/article/details/8551918

Http://www.2cto.com/kf/201207/144771.html

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.