General Android App code confuses the ultimate solution "go"

Source: Internet
Author: User
Tags eventbus

Although the app is not so tall, but the confusion of the code represents the programmer's sense of responsibility for the app, but also a little guarantee of the security of the app. Today I will do the process of Android confusion and share to everyone, but also to avoid people less detours, less jump pits.

This blog confuses the IDE development environment based on Android studio.

In fact, in the Android studio confusion, basically is the operation of the Proguard-rules.pro file. The process of confusion can also be traced in a regular way. Here I'll take a few parts to describe the obfuscation process separately.

(1) How to turn on confusion.

(2) Confusion of the public part.

(3) requires that we do not confuse the code.

(4) How to confuse third-party jar packages under Libs.

(5) Complie of third party jar packages.

(6) How to confuse code comments.

Okay, everybody ready? The following I will be journal the way to introduce you separately! (O (∩_∩) o haha ~)

1. How to turn on confusion

Start confusing very simply, find your project module in Android Studio Build.gradle, as shown in:

Setting minifyenabled to True will be OK.

2. Public sector

In the process of confusion, a part is fixed. Below I will list the modules that remain unchanged, just copy the code.

#1. Basic Command Area-optimizationpasses 5-Dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontskipnonpubliclibraryclassmembers-dontpreverify-verbose-ignorewarning-printmapping proguardMapping.txt-optimizations!code/simplification/cast,!field/*,!class/merging/*-keepattributes *annotation*,innerclasses-keepattributes signature-keepattributes SourceFile, linenumbertable#2. Default reserved-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.view.view-keep public class Com.android.vending.licensing.ilicensingservice-keep class android.support.** {*;} -keepclasseswithmembernames class * {native <methods>;} -keepclassmembers class * extends android.app.activity{public void * (Android.view.View);}    -keepclassmembers enum * {public static **[] values (); public static * * VALUEOF (java.lang.String);} -keep public class * Extends android.view.view{* * * get* ();    void set* (* * *);    Public <init> (Android.content.Context);    Public <init> (Android.content.Context, Android.util.AttributeSet); Public <init> (Android.content.Context, android.util.AttributeSet, int);}    -keepclasseswithmembers class * {public <init> (Android.content.Context, Android.util.AttributeSet); Public <init> (Android.content.Context, android.util.AttributeSet, int);} -keep class * Implements android.os.Parcelable {public static final Android.os.parcelable$creator *;}    -keepclassmembers class * Implements Java.io.Serializable {static final long serialversionuid;    private static final java.io.objectstreamfield[] Serialpersistentfields;    private void WriteObject (Java.io.ObjectOutputStream);    private void ReadObject (Java.io.ObjectInputStream);    Java.lang.Object Writereplace (); Java.lang.Object readresolve ();} -keep class * *. r$* {*;} -keepclassmembers class * {void * (**on*event);} #3. Webview-keepclassmembers class Fqcn.of.javasCript.interface.for.webview {public *;} -keepclassmembers class * extends Android.webkit.webViewClient {public void * (Android.webkit.WebView, java.lang.String    , Android.graphics.Bitmap); public Boolean * (Android.webkit.WebView, java.lang.String);} -keepclassmembers class * extends Android.webkit.webViewClient {public void * (Android.webkit.webView, jav.lang.String) ;}

The above is a fixed part.

3. We don't need to confuse the code

Does not confuse with the keyword-keep to decorate. The part that is not confused is probably divided into the following modules:

(1) Entity class, JSON parsing class

(2) Third party jar package

(3) JS and WebView call module

(4) Reflection-related classes and methods

is probably the above several modules, the following view does not confuse the code:

#1. Entity classes
class com.xx.xx.entity.** {*;}
#2. Third party Packages
#eventBus class * {    <methods>;} enum org.greenrobot.eventbus.** {*;} class extends org.greenrobot.eventbus.util.ThrowableFailureEvent {    <init>(java.lang.Throwable);}
#3. Classes that are called with JS are not writable
#4. Reflection-related classes and methods
class com.xx.xx.xx.xx.view.** {*;} class com.xx.xx.xx.xx.xx.** {*;}

How to confuse third-party jar packages under 4.libs
The way to keep the jar package under Libs is also simple, using the-keep keyword:
Locate the Libs directory, open the relative jar file, find the corresponding package name, and add the following code:
-keep class Package name. * * {*;}
5.complie obfuscation of third-party jar packages
Complie's third-party jar packages are confused in the same way as Libs, just open:
Open the corresponding reference jar file and use the same
-keep class Package name. * * {*;}
6. How code comments are confused
We have definitely used annotated code in the project, such as a knife (butterknife). You need to use @bind to modify the variables. The following code is required to keep this comment:
class butterknife.** {*;} -dontwarn butterknife.internal.**-keep class **$ $ViewBinder {*;} class * {    @butterknife. * <fields>;} class * {    @butterknife. * <methods>;}

Emm ... Say to yourself, if the butterknife version is lower, you may want to replace the third line with

-Keep class **$$viewinjector{*;}

General Android App code confuses the ultimate solution "go"

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.