Android code obfuscation and project release method record

Source: Internet
Author: User
Tags xml attribute

Android code obfuscation and project release method record
Zookeeper Android code obfuscation and project release procedure record

I have compiled a document for obfuscation and release of the Android project. I suddenly thought about writing a blog and sharing it. If so, I will have this article.

Android code obfuscation and project release procedure record

1. Clear debugging information in the Code, such as Log and System. out.

2. Modify the version to the current version in the configuration file. to update the database, modify the database version in the configuration class or configuration file.

3. Set the debugable of the project to false in the configuration file.

4. Create a signature certificate keystore File

In the project project.properitesfile of the project, the syntax sentence proguard.configpolicproguard-project.txt is used to specify the obfuscation rule file.

Configure the proguard-project.txt file in Step 6

7. If the Project references the Library project, Eclipse will automatically generate android. library. reference.1.. n = ../LibraryProjectName in the Project. properties file.

8. If the project contains svntmp (usually located in the bin folder of the project), delete it in time during packaging. Otherwise, packaging may fail.

9. Package and install and test the project (it is best to use the existing generated package for upgrade testing)

Appendix: proguard-project.txt and related instructions:

# This is a configuration file for ProGuard.

# Http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use

# Proguard-android.txt configuration file instead of this one, which

# Turns off the optimization flags. Adding optimization introduces

# Certain risks, since for example not all optimizations saved med

# ProGuard works on all versions of Dalvik. The following flags turn

# Off various optimizations known to have issues, but the list may not

# Be complete or up to date. (The "arithmetic" optimization can be

# Used if you are only targeting Android 2.0 or later.) Make sure you

# Test thoroughly if you go this route.

-Optimizations! Code/simplification/arithmetic ,! Code/simplification/cast ,! Field /*,! Class/merging /*

-Optimizationpasses 5

-Allowaccessmodification

-Dontpreverify

#-Dontoptimize

# The remainder of this file is identical to the non-optimized version

# Of the Proguard configuration file (could t that the other file has

# Flags to turn off optimization ).

-Dontusemixedcaseclassnames

-Dontskipnonpubliclibraryclasses

-Keepattributes Signature

-Verbose

-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

-Keepattributes * Annotation *

-Keep public class com. google. vending. licensing. ILicensingService

-Keep public class com. android. vending. licensing. ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native

-Keepclasseswithmembernames class *{

Native ;

}

# Keep setters in Views so that animations can still work.

# See http://proguard.sourceforge.net/manual/examples.html#beans

#-Keepclassmembers public class * extends android. view. View {

# Void set *(***);

# *** Get *();

#}

# We want to keep methods in Activity that cocould be used in the XML attribute onClick

-Keepclassmembers class * extends android. app. Activity {

Public void * (android. view. View );

}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations

-Keepclassmembers enum *{

Public static ** [] values ();

Public static ** valueOf (java. lang. String );

}

-Keep class * implements android. OS. Parcelable {

Public static final android. OS. Parcelable $ Creator *;

}

-Keepclassmembers class **. R$ *{

*;

}

# The support library contains references to newer platform versions.

# Don't warn about those in case this app is linking against an older

# Platform version. We know about them, and they are safe.

-Keep class * extends android. view. View {*;}

-Keep class * extends android. app. Dialog {*;}

-Keep class * implements java. io. Serializable {*;}

#-Ignorewarnings

-Libraryjars libs/locSDK_4.1.jar

-Libraryjars libs/pinyin4j-2.5.0.jar

-Libraryjars libs/libammsdk. jar

-Libraryjars libs/WebtrendsAndroidClientLib. jar

#-Libraryjars libs/afinallib. jar

#-Libraryjars libs/stickylistheaders_lib.jar

-Keep class android. support. v4 .**{*;}

-Keep class com. emilsjolander .**{*;}

-Keep class org. kobjects .**{*;}

-Keep class org. kxml2 .**{*;}

-Keep class org. xmlpull .**{*;}

-Keep class net. tsz .**{*;}

-Keep class com. hp .**{*;}

-Keep class com. baidu .**{*;}

-Keep class net. sourceforget .**{*;}

-Keep class com. tencent .**{*;}

-Dontwarn demo .**

-Keep class demo {*;}

-Keep class com. wly. xxx. bean .**{*;}

-Keep class com. wly. xxx. tool. DbModelUtils {*;}

-Keep class com. wly. xxx. tool. JsonUtils {*;}

-Keep class com. wly. xxx. activity. InsuranceQuotesActivity

-Keep public class com. wly. xxx. activity. InsuranceQuotesActivity $ MyJavaScriptInterface

-Keep public class * implements com. wly. xxx. activity. InsuranceQuotesActivity $ MyJavaScriptInterface

-Keepclassmembers class com. wly. xxx. activity. InsuranceQuotesActivity $ MyJavaScriptInterface {

Public *;

Private *;

}

File description:

0. The above files are copied from the project developed by the author. For the purpose of project protection, the project package name has been replaced by com. wly. xxx. You can modify it based on your project!

1. The blue content is generic and can be copied and pasted;

2. The Orange content is used to specify the jar files used in the Program (you can see that the referenced Library Project does not need to be included because they have already been specified in the project. properties file ).

3. The red content is used to indicate the content in the referenced jar package that is retained (not obfuscated.

4. The grass green content is used to indicate that the entity classes under the Local bean file are not obfuscated.

5. The Purple content is used to indicate that classes with local reflection are not obfuscated.

6. The green content is used to deal with the call process between Web JS and local native components in particular.

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.