Android Obfuscation code details and examples

Source: Internet
Author: User
Tags config final mail

Android Obfuscation Code details and examples

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 ;

}

-keepclasseswithmembernames class * {

Public (Android.content.Context, Android.util.AttributeSet);

}

-keepclasseswithmembernames class * {

Public (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 (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:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 # to enable Proguard in your project, edit Project.Properties # to define the Proguard.config property as described in th at 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, the # http://developer.android.com/guide/developing/tools/proguard.html   # ADD any project SPE Cific Keep options:   # IF your project uses WebView with JS, uncomment the following the Specify fully Alified class name to the JavaScript interface # class: #-keepclassmembers class Fqcn.of.javascript.interface.for.webview {# Public *; #}-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verb Ose-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.andro id.**{*}  -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 * Exte NDS Android.content.broadcastreceiver-keep public class * extends Android.content.contentprovider-keep public class * EX Tends Android.app.backup.backupagenthelper-keep public CLass * extends Android.preference.preference-keep public class * Extends android.support.v4.**-keep public class Com.and Roid.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 clas S * 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.** {*;} K Eep class com.j256.ormlite.stmt.** {*;}  -dontwarn android.support.v4.**-dontwarn org.apache.commons.net.**-don Twarn com.tencent.**  -keepclasseswithmembernames class * {native <methods>;}  -keepclasseswithmember Names class * {public <init> (Android.content.Context, Android.util.AttributeSet);}  - Keepclasseswithmembernames class * {public <init> (Android.content.Context, android.util.AttributeSet, int);} & nbsp -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.** &N Bsp -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 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

?

1 2 3 4 5 -keep class javax.mail.**{*}-keep class com.sun.mail.**{*;-keep class javax.activation.**{*;}-keep class Org.apache. harmony.**{*}-keep class java.security.**{*;} <br>

?

> #解 Summary: 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.**
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.