Enable Android progurad in the case of multiple JAR lib
2012-07-24 15:20
691 查看
View the version of Proguard:
1.open command window of windows.
2.enter the folder of proguard,step into bin directory.
cd <your SDK path>\android-sdk\tools\proguard\bin
3.run proguard
A.Normal Condition
Set the configuration file for progurad in project.properties:
default proguard.cfg:
Now the system will use the configurations in proguard.cfg when enable proguard.If you remove the blue line(just add '#' before it to make annotation),the proguard function will be shutdown.As a result,you apps can be decompiled very easily.Of course,it still can be decompiled if you set the proguard,but the result they get is obscure.So,for sake of security,you had better enable the proguard.
B.Multiple Jar Package
If you add other jar package to lib and use it in code,it may run well when you debug your project.However,while you are exporting signed application package,the question comes:
1.According to the error infomation,I should specify additional library jars (using '-libraryjars').
My file tree:
ProGuard outputs the following files after it runs:
Describes the internal structure of all the class files in the
Lists the mapping between the original and obfuscated class, method, and field names. This file is important when you receive a bug report from arelease build, because it translates the obfuscated stack trace back to the original class, method, and member names. See Decoding ObfuscatedStack Traces for more information.
Lists the classes and members that are not obfuscated
Lists the code that was stripped from the
These files are located in the following directories:
so I add the following to the end of proguard.cfg:
Shit! The errors still occur.
2.Then I consulted google and realized that I just need to enable proguard for my own code,needn't for the external jar libs.
refer: http://hi.baidu.com/bufferhayes/item/346c3a0a8148a16ad55a1108
So I modifed the content:
you can alse add the following if necessary:
Keep the class which may throw errors.The class and package name can be obtained from the Referenced Libraries directory.
Then I can generate the apk succesfully.
And the you can install it and maybe run it normally,but I still get errors:Can't find the my custom view in xml file!
The activity related to custom views all crashed!(Others can)
3.Someone pointed that it is caused by the bugs of the Proguard(4.7) itself.
So I replace it with 4.7 beta1.(just need to override the tools\proguard folder with 4.7beta1's contents)....
ADB server didn't ACK:
Try below steps:
Close the Eclipse if running
Go to the platform-tools directory in Command Prompt
type
then type
No error message is thrown while starting ADB server, then adb is started successfully.
Now you can start Eclipse again.
1.open command window of windows.
2.enter the folder of proguard,step into bin directory.
cd <your SDK path>\android-sdk\tools\proguard\bin
3.run proguard
A.Normal Condition
Set the configuration file for progurad in project.properties:
# This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system use, # "ant.properties", and override values to adapt the script to your # project structure. proguard.config=proguard.cfg # Project target. target=android-8
default proguard.cfg:
-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -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 -keep public class com.android.vending.licensing.ILicensingService -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }
Now the system will use the configurations in proguard.cfg when enable proguard.If you remove the blue line(just add '#' before it to make annotation),the proguard function will be shutdown.As a result,you apps can be decompiled very easily.Of course,it still can be decompiled if you set the proguard,but the result they get is obscure.So,for sake of security,you had better enable the proguard.
B.Multiple Jar Package
If you add other jar package to lib and use it in code,it may run well when you debug your project.However,while you are exporting signed application package,the question comes:
[2012-07-23 16:00:48 - AndroidReader] Proguard returned with error code 1. See console [2012-07-23 16:00:48 - AndroidReader] Warning: nl.siegmann.epublib.utilities.StreamWriterDelegate: can't find superclass or interface javax.xml.stream.XMLStreamWriter [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find superclass or interface org.apache.tools.ant.Task [2012-07-23 16:00:48 - AndroidReader] Warning: nl.siegmann.epublib.utilities.StreamWriterDelegate: can't find referenced class javax.xml.stream.XMLStreamWriter ...... [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find referenced class org.apache.tools.ant.Task [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find referenced class org.apache.tools.ant.BuildException ...... [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find referenced class org.apache.tools.ant.Task [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.JDomSerializer: can't find referenced class org.jdom.DefaultJDOMFactory ...... [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.JDomSerializer: can't find referenced class org.jdom.Element [2012-07-23 16:00:48 - AndroidReader] You should check if you need to specify additional program jars. [2012-07-23 16:00:48 - AndroidReader] Warning: there were 80 unresolved references to classes or interfaces. [2012-07-23 16:00:48 - AndroidReader] You may need to specify additional library jars (using '-libraryjars'). [2012-07-23 16:00:48 - AndroidReader] java.io.IOException: Please correct the above warnings first. [2012-07-23 16:00:48 - AndroidReader] at proguard.Initializer.execute(Initializer.java:321) [2012-07-23 16:00:48 - AndroidReader] at proguard.ProGuard.initialize(ProGuard.java:211) [2012-07-23 16:00:48 - AndroidReader] at proguard.ProGuard.execute(ProGuard.java:86) [2012-07-23 16:00:48 - AndroidReader] at proguard.ProGuard.main(ProGuard.java:492)
1.According to the error infomation,I should specify additional library jars (using '-libraryjars').
My file tree:
ProGuard outputs the following files after it runs:
dump.txt
Describes the internal structure of all the class files in the
.apkfile
mapping.txt
Lists the mapping between the original and obfuscated class, method, and field names. This file is important when you receive a bug report from arelease build, because it translates the obfuscated stack trace back to the original class, method, and member names. See Decoding ObfuscatedStack Traces for more information.
seeds.txt
Lists the classes and members that are not obfuscated
usage.txt
Lists the code that was stripped from the
.apk
These files are located in the following directories:
<project_root>/bin/proguardif you are using Ant.
<project_root>/proguardif you are using Eclipse.
so I add the following to the end of proguard.cfg:
-libraryjars lib/acra-4.2.3.jar -libraryjars lib/epublib-core-latest.jar -libraryjars lib/htmlcleaner-2.2.jar -libraryjars lib/slf4j-api-1.6.4.jar -libraryjars lib/slf4j-jdk14-1.6.4.jar -libraryjars lib/xnio-api-2.0.2.GA.jar
Shit! The errors still occur.
2.Then I consulted google and realized that I just need to enable proguard for my own code,needn't for the external jar libs.
refer: http://hi.baidu.com/bufferhayes/item/346c3a0a8148a16ad55a1108
So I modifed the content:
-keep class nl.siegmann.epublib.** {*;} -keep class org.htmlcleaner.** {*;} -keep class org.slf4j.** {*;} -dontwarn nl.siegmann.epublib.** -dontwarn org.htmlcleaner.** -dontwarn org.slf4j.** -libraryjars lib/acra-4.2.3.jar -libraryjars lib/epublib-core-latest.jar -libraryjars lib/htmlcleaner-2.2.jar -libraryjars lib/slf4j-api-1.6.4.jar -libraryjars lib/slf4j-jdk14-1.6.4.jar
you can alse add the following if necessary:
-keep interface nl.siegmann.epublib.** {*;} -keep interface org.htmlcleaner.** {*;} -keep interface org.slf4j.** {*;}
Keep the class which may throw errors.The class and package name can be obtained from the Referenced Libraries directory.
Then I can generate the apk succesfully.
And the you can install it and maybe run it normally,but I still get errors:Can't find the my custom view in xml file!
The activity related to custom views all crashed!(Others can)
3.Someone pointed that it is caused by the bugs of the Proguard(4.7) itself.
So I replace it with 4.7 beta1.(just need to override the tools\proguard folder with 4.7beta1's contents)....
ADB server didn't ACK:
Try below steps:
Close the Eclipse if running
Go to the platform-tools directory in Command Prompt
type
adb kill-server
then type
adb start-server
No error message is thrown while starting ADB server, then adb is started successfully.
Now you can start Eclipse again.
相关文章推荐
- A case study in Free vs. Paid and the value of advertising
- location of the android sdk has not been setup in the preferences如何解决
- Eclipse运行Android项目提示sdk\build-tools\26.0.0\lib\dx.jar Unable to build: the file dx.jar was not loade
- “Location of the Android SDK has not been set up in the preferences”问题的解决
- The Android Evolution of Supporting Multiple Screens
- the case of using Json in my working
- Django URLs error: view must be a callable or a list/tuple in the case of include()
- Android Error:The number of method references in a .dex file cannot exceed 64K.
- how to put the text on the left of a radio button in android
- The project is using an unsupported version of the Android Gradle plug-in
- [Android 問題] How to Add a Button in ListView, and Make the Event of onClick and onItemClick Coexist?
- TypeError: view must be a callable or a list/tuple in the case of include().解决办法
- The JAR of this class file belongs to container 'Android Private Libraries' Android查看外部依赖jar的源码问题解
- 关于Location of the Android SDK has not been setup in the preferences的解决方法
- Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre7\..\lib\tools.jar
- The insecurity of home digital voice assistants -amzon alexa as a case study
- 【Android】-- 处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k的两种办法
- Error:The project is using an unsupported version of the Android Gradle plug-in (0.8.3). The recomme
- Android RecyclerView的案例讲述和"The hierarchy of the type ViewHolder is inconsistent"错误解决
- 跟踪算法基准--Tracking the Trackers: An Analysis of the State of the Art in Multiple Object Tracking