Android Implementation code obfuscation

Source: Internet
Author: User

For the APK using the signature, it is often possible to see the code implementation of the class file after the anti-compilation that is used frequently. For anti-compilation viewable personal blogs click the open link

The use of code obfuscation can be such a normal anti-compilation failure. Many other confusing mechanisms are found on the official website http://developer.android.com/guide/developing/tools/proguard.html

1. In Build.grandle, the rules are written in Proguard-rules.pro. You can also define a file and replace it yourself, for example, the proguard-project.txt that eclipse often uses

Buildtypes {    Release {        signingconfig signingconfigs.release        true        proguardfiles Getdefaultproguardfile (' proguard-android.txt 'proguard-rules.pro '    }}
2. Add the following code in the Proguard-rules.pro. Basically can cover all

-optimizationpasses5# specify the compression level of the Code-dontusemixedcaseclassnames# whether to use uppercase and lowercase blending-dontpreverify# whether to do pre-calibration when confusing-verbose# whether logs are logged when confused-dontwarncom.umeng.**#Keepcom.umeng.**all the classes and all the methods in this package are not confused. (Delete This sentence without the union's integration) -optimizations!code/simplification/arithmetic,!field/*,!class/merging/*# the algorithm used in the confusion-keeppublic class * Extends Android.app.Application# Keep What classes are not confused-keeppublic class * Extends Android.app.Service# Keep What classes are not confused-keeppublic class * Extends Android.content.BroadcastReceiver# Keep What classes are not confused-keeppublic class * Extends Android.content.ContentProvider# Keep What classes are not confused-keeppublic class * Extends Android.app.backup.BackupAgentHelper# Keep What classes are not confused-keeppublic class * Extends Android.preference.Preference# Keep What classes are not confused-keeppublic class Com.android.vending.licensing.ILicensingService# Keep What classes are not confused-keepclasseswithmembernamesClass * {# Keepnativemethod not to be confusednative <methods>;}-keepclasseswithmembersClass * {# Keep yourself defined the control class is not confusedPublic <init> (Android.content.Context, android.util.AttributeSet);}-keepclasseswithmembersClass * {# Keep yourself defined the control class is not confused
    Public <init> (Android.content.Context, Android.util.AttributeSet, int.);
}
-keepclassmembers
Class * extends Android.app.Activity {# Keep yourself defined the control class is not confused
public void * (Android.view.View);
}
-keepclassmembersEnum * {# Persist Enumerationenumclass not to be confused
public static **[] values ();
public static * * VALUEOF (java.lang.String);
}
-keep
Class * Implements Android.os.Parcelable {# Keepparcelablenot to be confused
public static final Android.os.parcelable$creator *;
}

3,when confusing code through Android Studio , the jar in the Lib folder has been added to the packaging script by default, so you do not need to manually join it again. Otherwise, the "Java.io.IOException:The same input jar is specified twice" error appears.

4. Make a signed apk to decompile, view the code, confuse and confuse the preceding diagram for example, the very many classes in the package are renamed and the confused apk size is smaller and the execution is smoother


Android Implementation code obfuscation

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.