Android Obfuscation Code Summary

Source: Internet
Author: User

In order to prevent the results of their own work stolen by others, confusing code can effectively prevent the anti-compilation, the following to summarize the following steps to confuse the code:

1. It may be noted that a new project will see the project under the Proguard-project.txt a file, which is very important for confusing code, if you accidentally deleted it, it's okay, copy one from somewhere else.

2. The most important thing is to add the confusing statement to the Proguard-project.txt:

A. Declare all your jar packages, for example:
-libraryjars Libs/apns_1.0.6.jar
-libraryjars libs/armeabi/libbaidumapsdk_v2_3_1.so
-libraryjars libs/armeabi/liblocsdk4.so
-libraryjars Libs/baidumapapi_v2_3_1.jar
-libraryjars Libs/core.jar
-libraryjars Libs/gesture-imageview.jar
-libraryjars Libs/gson-2.0.jar
-libraryjars Libs/infogracesound.jar
-libraryjars Libs/locsdk_4.0.jar
-libraryjars Libs/ormlite-android-4.48.jar
-libraryjars Libs/ormlite-core-4.48.jar
-libraryjars Libs/universal-image-loader-1.9.0.jar

B. Make a statement that you do not need to confuse, because some of the classes that are confused can cause the program to compile without passing, as follows:

-keep public class * extends Android.app.Fragment
-keep public class * extends Android.app.Activity
-keep public class * extends Android.app.Application
-keep public class * extends Android.app.Service
-keep public class * extends Android.content.BroadcastReceiver
-keep public class * extends Android.content.ContentProvider
-keep public class * extends Android.app.backup.BackupAgentHelper
-keep public class * extends Android.preference.Preference
-keep public class * extends android.support.v4.**
-keep public class Com.android.vending.licensing.ILicensingService

--The above is the class in the API, it is best to avoid confusion

Some are very special, such as Baidu Map, you need to add the following statement:

-keep class com.baidu.** {*;}
-keep class vi.com.gdi.bgl.android.**{*;}

In my experience, it is best to avoid confusion in the general model (model is irrelevant, not confusing, not much) such as:

-keep class com.bank.pingan.model.** {*;}
The following is a statement about Umeng sharing statistics to avoid confusion

-dontwarn android.support.v4.**
-dontwarn org.apache.commons.net.**
-dontwarn com.tencent.**

-keepclasseswithmembernames class * {
Native <methods>;
}

-keepclasseswithmembernames class * {
Public <init> (Android.content.Context, Android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
Public <init> (Android.content.Context, Android.util.AttributeSet, int.);
}

-keepclassmembers enum * {
public static **[] values ();
public static * * VALUEOF (java.lang.String);
}

-keep class * Implements Android.os.Parcelable {
public static final Android.os.parcelable$creator *;
}

-keepclasseswithmembers class * {
Public <init> (Android.content.Context);
}

-dontshrink
-dontoptimize
-dontwarn com.google.android.maps.**
-dontwarn Android.webkit.WebView
-dontwarn com.umeng.**
-dontwarn com.tencent.weibo.sdk.**
-dontwarn com.facebook.**

-keep enum com.facebook.**
-keepattributes exceptions,innerclasses,signature
-keepattributes *annotation*
-keepattributes sourcefile,linenumbertable

-keep public Interface com.facebook.**
-keep public Interface com.tencent.**
-keep public Interface com.umeng.socialize.**
-keep public Interface com.umeng.socialize.sensor.**
-keep public Interface com.umeng.scrshot.**

-keep public class Com.umeng.socialize.* {*;}
-keep public class javax.**
-keep public class android.webkit.**

-keep class com.facebook.**
-keep class com.umeng.scrshot.**
-keep public class com.tencent.** {*;}
-keep class com.umeng.socialize.sensor.**

-keep class Com.tencent.mm.sdk.openapi.WXMediaMessage {*;}

-keep class com.tencent.mm.sdk.openapi.** implements Com.tencent.mm.sdk.openapi.wxmediamessage$imediaobject {*;}

-keep class Im.yixin.sdk.api.YXMessage {*;}
-keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.yxmessage$yxmessagedata{*;}

-keep public class [Your_pkg]. r$*{
public static final int *;
}

3. The above work is complete, the confusion work completes the more than half, the final need to do is to add your confused file in the Project.Properties file declaration, as follows:

Proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

4. OK, the final step, hit the signature package test, if there is a problem, look closely at the log may have a class can not be confused, then you have to add to the Proguard-project.txt file

-------above is the whole process of confusing the code.

Finally, paste all the Proguard-project.txt code:

# to enable Proguard in your project, edit project.properties# to define the Proguard.config property as described  file.## ADD Project specific Proguard rules here.# by default, the ' flags in ' This file is appended to ' flags specified# in  ${sdk.dir}/tools/proguard/proguard-android.txt# You can edit the include path and order by changing the proguard# include Property in project.properties.## to more details, see# Http://developer.android.com/guide/developing/tools/proguard . html# ADD any project specific keep options here:# If your project uses WebView with JS, uncomment the following# and SPE Cify the fully qualified class name to the JavaScript interface# Class:#-keepclassmembers class Fqcn.of.javascript.interfa Ce.for.webview {# public *;#}-optimizationpasses 5- Dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optimizations!code/ Simplification/arithmetic,!field/*,!class/merging/*-keepattributes *annotation*-keepattributes Signature-libraryjars Libs/apns_1.0.6.jar-libraryjars Libs/armeabi/libbaidumapsdk_v2_3_1.so-libraryjars libs/armeabi/ Liblocsdk4.so-libraryjars Libs/baidumapapi_v2_3_1.jar-libraryjars Libs/core.jar-libraryjars libs/ Gesture-imageview.jar-libraryjars Libs/gson-2.0.jar-libraryjars Libs/infogracesound.jar-libraryjars libs/locSDK_ 4.0.jar-libraryjars Libs/ormlite-android-4.48.jar-libraryjars Libs/ormlite-core-4.48.jar-libraryjars libs/ Universal-image-loader-1.9.0.jar-keep class com.baidu.** {*;}-keep class vi.com.gdi.bgl.android.**{*;} -keep public class * extends Android.app.fragment-keep public class * extends Android.app.activity-keep public class * E Xtends Android.app.application-keep public class * extends Android.app.service-keep public class * extends Android.conten T.broadcastreceiver-keep public class * extends Android.content.contentprovider-keep public class * extends Android.app.backup.backupagenthelper-keep public class * extends Android.preference.preference-keep public class * Extends android.suPport.v4.**-keep public class Com.android.vending.licensing.ilicensingservice-keep class com.google.gson.stream.** { *; }-keep class com.google.gson.examples.android.model.** {*;} -keep class com.uuhelper.application.** {*;} -keep class net.sourceforge.zbar.** {*;} -keep class com.google.android.gms.** {*;}-keep class com.bank.pingan.model.** {*;} -keep public class * extends Com.j256.ormlite.android.apptools.ormlitesqliteopenhelper-keep public class * extends Com.j256.ormlite.android.apptools.openhelpermanager-keep class  Com.android.vending.licensing.ilicensingservice-keep class android.support.v4.** {*;}  -keep class org.apache.commons.net.** {*;}   -keep class com.tencent.** {*;}  -keep class com.umeng.** {*;}  -keep class com.umeng.analytics.** {*;}  -keep class com.umeng.common.** {*;}   -keep class com.umeng.newxp.** {*;}  -keep class com.j256.ormlite.** {*;}  -keep class com.j256.ormlite.android.** {*;}  -keep class com.j256.ormlite.field.** {*;} -keEP Class com.j256.ormlite.stmt.** {*;}-dontwarn android.support.v4.**-dontwarn org.apache.commons.net.**-dontwarn Co m.tencent.**-keepclasseswithmembernames class * {native <methods>;} -keepclasseswithmembernames class * {public <init> (Android.content.Context, android.util.AttributeSet);} -keepclasseswithmembernames class * {public <init> (Android.content.Context, android.util.AttributeSet, int);}    -keepclassmembers enum * {public static **[] values (); public static * * VALUEOF (java.lang.String);} -keep class * Implements android.os.Parcelable {public static final Android.os.parcelable$creator *;} -keepclasseswithmembers class * {public <init> (android.content.Context);} -dontshrink-dontoptimize-dontwarn Com.google.android.maps.**-dontwarn Android.webkit.webview-dontwarn com.umeng.* *-dontwarn com.tencent.weibo.sdk.**-dontwarn com.facebook.**-keep enum Com.facebook.**-keepattributes Exceptions, Innerclasses,signature-keepattributes *annotatioN*-keepattributes Sourcefile,linenumbertable-keep public Interface Com.facebook.**-keep public interface com.tencent. **-keep public Interface Com.umeng.socialize.**-keep public interface Com.umeng.socialize.sensor.**-keep Public Interface Com.umeng.scrshot.**-keep public class com.umeng.socialize.* {*;} -keep public class Javax.**-keep public class Android.webkit.**-keep class Com.facebook.**-keep class Com.umeng.scrshot. **-keep public class com.tencent.** {*;} -keep class Com.umeng.socialize.sensor.**-keep class Com.tencent.mm.sdk.openapi.WXMediaMessage {*;} -keep class com.tencent.mm.sdk.openapi.** implements Com.tencent.mm.sdk.openapi.wxmediamessage$imediaobject {*;} -keep class Im.yixin.sdk.api.YXMessage {*;} -keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.yxmessage$yxmessagedata{*;} -keep public class [Your_pkg]. r$*{public static final int *;}


Ok,that ' s all.

--thank you!

Android Obfuscation Code Summary

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.