About Android Code obfuscation

Source: Internet
Author: User

The need for code confusion must be known to all. Can see this article, explain the code confusion logic, the way is very familiar, here is no longer introduced from 0.

Here are just a few common problems and workarounds for using the obfuscation tool Proguard:

1. About Reflection

Reflection is concerned with the names of the class and Class fields (field) (Stirng form), so use to the reflected entity class, avoid confusion. One by one how to set a field personally, I don't think it's necessary.

A. Keep the specified class
-keep class com.yourpkg.model.yourcls{
*;
}

b, keep all classes under the specified package
-keep class com.yourpkg.model.**{
*;
}

2, about Gson and TypeToken

This problem bothered me for several days, finally found a solution in stack overflow, I am a superficial understanding person, at least for now. Finding a solution is a very expensive job, for me so no cost of people, encounter problems as long as can solve the OK.

##---------------Begin: proguard configuration for Gson  ----------# Gson uses generic type information stored in a class file when working with fields. Proguard# removes such information by default, so configure it to keep all of it.-keepattributes Signature# Gson specific classes-keep class sun.misc.Unsafe { *; }#-keep class com.google.gson.stream.** { *; }# Application classes that will be serialized/deserialized over Gson-keep class com.google.gson.examples.android.model.** { *; }##---------------End: proguard configuration for Gson  ----------

3, about the third party jar package

Third-party jars are frequently referenced in the project, which, if involved in confusion, can cause unknown errors, so third-party jar packages are excluded.

-libraryjars libs/third party. Jar

Finally provide a stack overflow found on the general confusion configuration, each code specifically what meaning, I believe we will find degrees Niang or API, typesetting level is too poor, a lot of forgive.

# #---------------Begin:proguard configuration common for all Android apps-----------optimizationpasses 5- Dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontskipnonpubliclibraryclassmembers-dontpreverify-verbose-dum P class_files.txt-printseeds seeds.txt-printusage unused.txt-printmapping mapping.txt-optimizations!code/ Simplification/arithmetic,!field/*,!class/merging/*-allowaccessmodification-keepattributes *Annotation*- Renamesourcefileattribute sourcefile-keepattributes sourcefile,linenumbertable-repackageclasses '-keep public Class * Extends Android.app.activity-keep public class * extends Android.app.application-keep public class * extends Andro Id.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 Com.android.vending.licensing.ILicensingService-dontnote com.android.vending.licensing.ilicensingservice# explicitly preserve all serialization members. The Serializable interface# is only a marker interface, so it wouldn ' t save them.-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 ();} # Preserve All native method names and the names of their Classes.-keepclasseswithmembernames class * {native <meth Ods>;} -keepclasseswithmembernames class * {public <init> (Android.content.Context, android.util.AttributeSet);} -keepclasseswithmembernames class * {public <init> (Android.content.Context, android.util.AttributeSet, int);} # Preserve static fields of inner classes of R classes, might be accessed# through INTROspection.-keepclassmembers class * *. r$* {public static <fields>;} # Preserve The special static methods that is required in all enumeration Classes.-keepclassmembers enum * {public St    atic **[] VALUES (); public static * * VALUEOF (java.lang.String);} -keep public class * {public protected *;} -keep class * Implements android.os.Parcelable {public static final Android.os.parcelable$creator *;} # #---------------End:proguard configuration common for all Android apps----------

About Android Code obfuscation

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.