Proguard optimized Android logs

Source: Internet
Author: User

Android application development process, will generally join a variety of log printing, easy to debug code, Android.util.Log method is often used. If the app always outputs log.i or log.d content in the background, the overall efficiency of the application is affected, in addition to the overhead of increasing the system. Proguard compresses, optimizes, and confuses code by removing code that has never been used and renaming classes, fields, and methods with obscure names. The result is a smaller. apk file that is more difficult to reverse engineer and therefore more secure.

1 Basic Configuration

Create a new Android project in Eclipse, and a proguard-project.txt file will be created automatically at the root of the project. By default, new projects in Eclipse do not include the Proguard feature and need to modify the Project.Properties file. The "#" on the front end of the "#proguard. Config= ..." will be removed. The configuration information for "proguard.config=" consists of two parts: the default part and the project-specific section, which will be appended to the default section (such as a hint) to form the confusing configuration of the project, so if you need to configure the file to be confused according to your requirements, You only need to modify the proguard-project.txt.

2 tuning Logs

By default, the configuration of the previous section is not optimized, so we should replace "${sdk.dir}/tools/proguard/proguard-android.txt" in the Project.Properties file with "${sdk.dir} /tools/proguard/proguard-android-optimize.txt "so that the optimization function is not turned off.

The optimization log is mainly implemented by the following command:

-assumenosideeffects class_specification

This command points out which methods are non-side-effects. During the optimization phase, this command will remove calls to these methods.

3 Example

Follow the steps and methods described above, create a new project, and configure Proguard to add the following instruction in the Proguard-project.txt file.

-assumenosideeffects class Android.util.Log {             public  static int V (...);             public  static int i (...);             public  static int w (...);             public  static int d (...);   }

It is important to note that the run or buildproject/build all in eclipse generates the APK without confusing the code! "Export unsignedapplication Package ...", then follow the wizard and eventually generate an unsigned apk. The viewing effect can be opened with a 7z compression program, the Classes.dex of which is decompressed, converted to jar format with Dex2jar, and then opened with the Java Anti-coding tool Jd-gui, you will see the confusion of the code effect.



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.