Android Obfuscation Code and example _android

Source: Internet
Author: User

To prevent the results of their work from being stolen, confusing code can effectively prevent being decompile, the following is a summary of the following confusing code steps:

1. You may have noticed that a new project would see a file like this on the bottom of the project, which is important for confusing code, and if you accidentally delete it, it's okay, copy one from somewhere else proguard-project.txt.

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

A. Declare all your jar packs, 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 don't need to be confused because some classes are confusing and cause the program to compile and not pass, 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

--These are the classes in the API, and it's 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 confused and not much relationship) such as:

-keep class com.bank.pingan.model.** {*;}

Here's a statement about avoiding 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 completes, confuses the work to complete the half, finally needs to do is in the Project.Properties file adds your confusing document to affirm, as follows:
Proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

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

-------above is the whole process of confusing 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 in T 
Hat file. 
# ADD Project specific Proguard rules here. 
# By default, the flags in this file are 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 in Project.Properties. # for more details, and # http://developer.android.com/guide/developing/tools/proguard.html # ADD any project spec Ific Keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully Qualif 
IED class name to the JavaScript interface # class: #-keepclassmembers class Fqcn.of.javascript.interface.for.webview { 
# public *; #}-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optim Izations!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 * 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.**-ke 
EP 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.J 256.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 com.tencent.** 
Rnames 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.** 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.sc 
rshot.**-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 declaration:

The following is an instance of sending a message

-libraryjars.. /klowerbase/libs/mail-activation.jar
-libraryjars.. /klowerbase/libs/mail-additionnal.jar
-libraryjars.. /klowerbase/libs/mail.jar

2. Resolve mail sent by the times of abnormal

 -keep class javax.mail.**{*;} 
 -keep class com.sun.mail.**{*;} 
-keep class javax.activation.**{*;} 
-keep class org.apache.harmony.**{*;} 

#解决: 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 

Through this article I hope to help the Android development application using confusing code friends, thank you for your support for this site!

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.