Android (Java) Learning Note 128: Using Proguard to confuse Android code

Source: Internet
Author: User

1. Currently some tools, such as Apktool,dextojar, can be used to decompile our Android installation package to obtain the source code . In order to reduce being cracked, resulting in source code leakage, the program was stolen by others, and so on. We need to confuse the code , the Android SDK provides us with the proguard tool that can confuse the code (usually renamed with a meaningless name), and remove unused code, optimize and compress the program, This will increase the difficulty you want. The most recent project I did was to configure the confusing configuration, so I researched it and shared it here.

2. the above mentioned the removal of unused code, the program is optimized and compressed: This is the program's slimming

APK slimming usually has two lines,

    1. Removing useless code, such as referencing a larger LIB, uses only a few of these features. Other useless code can be removed.
    2. Removing useless resource files may be in a third-party lib, or it may be that a useless resource has been introduced in development
Remove useless code

Of course it's Proguard !

Gradle plug 0.14.0, Runproguard renamed to Minifyenabled

Remove Useless resources

Android Gradle plug starts with 0.14.0 and supports automatic removal of unused resources.

However, this switch is off by default. Can be opened in build type using shrinkresources true. Note that the use of this feature depends on the code shrinking, so minifyenabled must also be turned on.

  1. Support for automatic removal of unused resources

  2. OFF By default for now, enable by setting Shrinkresources to true in your release build types. Requires minifyenabled as well.

The specific configuration is as follows

Android {    Buildtypes {        release {            minifyenabled true            shrinkresources True        }}    }
Effect

Take an example of an app I'm developing

    • 2.02MB before use

    • 1.90MB after use

The effect is obvious!

Android (Java) Learning Note 128: Using Proguard to confuse Android code

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.