Confuse code with Android Proguard

Source: Internet
Author: User

Reference Document: http://blog.csdn.net/xueyepiaoling/article/details/8202359 reprinted from: http://glblong.blog.51cto.com/3058613/1263969

When creating a project in a new version of ADT, the mixed files are no longer proguard.cfg, but Project.Properties and Proguard-project.txt.

If you need to make a global mix of items, you only need to do one step:

The project.properties in the

The "#" of "# Proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt" will be removed.

If some code can not be confused, such as the need to add the so file, need to call the inside of the method, then call JNI Access so file method can not be mixed code. When exporting, you may not get an error. But when running on the phone, you need to call so file, it will be reported that such a method cannot be found. We need to use proguard-project.txt at this time.

In the old version, when the project was created, Proguard.cfg was given, but the new version created the project without any hint. This time you need to add proguard.cfg content to the Proguard-project.txt, and then edit according to your own needs.

==================proguard.cfg Anti-================================== compilation method

To enable Proguard-so-it runs as part of a Ant or Eclipse build, set the property in the proguard.config <project_root>/project.properties file. The path can be a absolute path or a path relative to the project ' s root.

If you left proguard.cfg the file under its default location (the project's root directory), you can specify it location like this:

Proguard.config=proguard.cfg

You can also move the "file to anywhere" want, and specify the absolute path to it:

Proguard.config=/path/to/proguard.cfg

When you build your application in release mode, either by running ant release or by using the " Export" Wizardin Eclipse, The build system automatically checks to see if the property is proguard.config set. If it is, Proguard automatically processes the application ' s bytecode before packaging everything to an .apk file. Building in debug mode does not invoke Proguard, because it makes debugging more cumbersome.

=========== "Turn" confusing file proguard.cfg detailed ======================================

-injars Androidtest.jar "jar Package Address"

-outjars out "Output address"

The jar of the library referenced by-libraryjars ' D:\android-sdk-windows\platforms\android-9\android.jar ', used to parse the jar class specified by Injars "

-optimizationpasses 5

-dontusemixedcaseclassnames "does not produce a variety of class names when confused"

-dontskipnonpubliclibraryclasses "Specifies that non-public library classes are not ignored. 】

-dontpreverify "No pre-check"

-verbose

-optimizations!code/simplification/arithmetic,!field/*,!class/merging/* "Optimization"

-keep public class * extends Android.app.Activity "Do not confuse and remain as is"

-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 Com.android.vending.licensing.ILicensingService

-keep Public Abstract Interface com.asqw.android.listener{

Public protected <methods>; "All methods are not confused"

}

-keep public class com.asqw.android{

public void Start (java.lang.String); "No confusion with this method"

}

-keepclasseswithmembernames class * {"protects the name of a member of a specified class and class if all the specified class members are present (after the compression step)"

Native <methods>;

}

-keepclasseswithmembers class * {"Protects the members of the specified class and class, but the condition is that all specified classes and class members are to be present." 】

Public <init> (Android.content.Context, Android.util.AttributeSet);

}

-keepclasseswithmembers class * {

Public <init> (Android.content.Context, Android.util.AttributeSet, int.);

}

-keepclassmembers class * extends Android.app.Activity {"Protects members of a specified class if this class is protected they will be better protected"

public void * (Android.view.View);

}

-keepclassmembers enum * {

public static **[] values ();

public static * * VALUEOF (java.lang.String);

}

-keep class * Implements Android.os.Parcelable {"Protection of members of specified class files and classes"

public static final Android.os.parcelable$creator *;

}

===================================== Common anomalies ===================================

Reference: http://blog.csdn.net/vrix/article/details/7100841

Several exceptions that often occur after adding a third-party jar package:

Proguard returned with error code 1.See console

Scenario 1:

Proguard returned with error code 1. See console

Error:c:/documents (the system cannot find the specified file)

Later found because the entire project was put on the desktop, and the desktop directory is c:/documents and settings/administrator/desktop, in which there are spaces, and proguard to compile the time is not allowed to have spaces

If the correct path is not good enough, delete Proguard directly.

Note: The SDK and program paths are best not to have whitespace

Scenario 2:

Proguard returned with error code 1. See console

Abnormal:

Java.lang.ArrayIndexOutOfBoundsException

Workaround: Change "-dontpreverify" in Proguard.cfg to "-dontoptimize"

Reference article: http://groups.google.com/group/android-developers/browse_thread/thread/eca3b0f5ce6ad00f

I delete the Proguard folder (which is empty at this time) in the project and then run the project again, OK.

Scenario 3:

[2011-10-21 13:22:32-zmksmarket_build_v1.0] Proguard returned with error code 1. See console

[2011-10-21 13:22:32-zmksmarket_build_v1.0] java.io.IOException:Can ' t read [[email protected]] (No such file or Directo Ry

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Inputreader.readinput (inputreader.java:230)

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Inputreader.readinput (inputreader.java:200)

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Inputreader.readinput (inputreader.java:178)

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Inputreader.execute (inputreader.java:100)

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Proguard.readinput (proguard.java:195)

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Proguard.execute (proguard.java:78)

[2011-10-21 13:22:32-zmksmarket_build_v1.0]

At Proguard. Proguard.main (proguard.java:499)

The reason for throwing such an exception is that the reference path of the third-party jar is incorrect, and the jar package that needs to be ignored is not found.

Confuse code with Android Proguard

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.