Android Obfuscation Code Rollup

Source: Internet
Author: User

In order to prevent others from being robbed of their own work, confusing code can be effectively prevented by anti-compilation, following the confusion summarized in the following code steps:

1. You may have noticed that a new item will be seen below the items that have this proguard-project.txt a file that the code can use for confusion is very important. Suppose you accidentally delete it, okay, come on

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

A. Declare all your jar packages, such as:
-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, such as the following:

-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 very special, such as Baidu Map, you need to add the following statement:

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

According to my experience. The general model is best to avoid confusion (model does not matter.) Not to confuse or have much to do with) such as:

-keep class com.bank.pingan.model.** {*;}
The following is a statement on the avoidance of confusion about Umeng sharing statistics

-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 is finished more than half. The last thing you need to do is add your confusion file to the Project.Properties file, for example, the following:

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

4. OK. Last step, hit the signature packet test. If there is a problem, look carefully 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 *;}
2015-05-25 Update
1. Project-dependent jar declarations:
The following is an example of sending a message
   -libraryjars. /klowerbase/libs/mail-activation.jar   -libraryjars. /klowerbase/libs/mail-additionnal.jar   -libraryjars. /klowerbase/libs/mail.jar
2. Resolve the mail to send the Times with an exception
   -keep class javax.mail.**{*;}   -keep class com.sun.mail.**{*;}  -keep class javax.activation.**{*;}  -keep class org.apache.harmony.**{*;}  -keep class java.security.**{*;}
#解决: Can ' t find referenced class Java.beans.beans-dontwarn Org.apache.commons.collections.beanmap-dontwarn Java.beans . * * #解决: Can ' t find referenced class Javax.security.sasl.sasl-dontwarn com.sun.mail.imap.protocol.**


Ok,that ' s all.

--thank you!

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Android Obfuscation Code Rollup

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.