Android java代码混淆
2013-10-16 10:20
363 查看
网上搜了很多资料,说在工程的根目录下有default.properties文件,在该文件下加上“proguard.config=proguard.cfg”,同时增加proguard.cfg文件,但我的工程下没找到这两个文件,不过找到一个proguard-project.txt的文件,进去看了看,说的很明白:To enable
ProGuard in your project, edit project.properties,好,进入project.properties,又提到:
To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
就是把上面的#去掉,然后把sdk.dir指向你的AndroidSDK的目录,我想那个proguard-android.txt应该是个模板,是个公用的模板,每个需要混淆的工程都会用到该文件。同时,proguard-project.txt又提到Add any project specific keep options
here,即具体到某个工程需要而编写的一些特定的混淆配置,需要写在proguard-project.txt文件中,比如暴露在AndroidManifest.xml中的类,service,activity等等,加入生成APK后,运行过程中,找不到某个类,如果不是jar库没有有效编译就去,那就是混淆器把这类给混淆了,运行时无法找到这个类,需要把这个类keep,保持原样。根据经验,一般只需要keep
类即可,对变量和函数一般不需要做处理
如何输出混淆的APK,右键工程--->Android Tools--->Export Unsigned Application Package。
但是用上述方法输出的apk无法安装,提示“应用程序未安装”,后来通过右键工程--->Android Tools--->Export Signed Application Package,然后开始自己新建一个key_store,设置好用
了!!!!
问题:
I am trying to use javamail in my Android app, but proguard complains about a whole load of stuff that it cannot find. I have tried various remedies that I have found while searching the internet, but nothing seems to work. Has
anyone got this thing working? Thanks.
I have added some -dontwarn commands to the defauly proguard.cfg, and succeeded in eliminating all of the warning messages except this one:
解决:
I am using the 2.1 SDK, which might make a difference. I also have a fairly complex email. But I have sorted it now, by upgrading to proguard 4.6 and adding the following lines to the head my proguard.cfg:
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
The last group of lines is non-trivial. I obtained it by running tar tf commands against each of the jars in the javamail package.
同时如果使用pop3接收邮件,应该加上-keep class com.sun.mail.pop3.** {*;},不然会爆出“javax.mail.nosuchproviderexception:pop3”异常,原因可能是proguard把类com.sun.mail.pop3也给混淆了,导致程序中找不到该类。
Update for SDK 17
Android SDK 17 introduces some changes in the way that jars are loaded. If you have a project that uses external jars, upgrading to SDK 17 or beyond will probably break it. To fix this, select Project > Properties > Java Build Path
> Order and Export from the menu, and check the boxes to left of the three jars used by javamail. This ensures that the jars get exported to the target build. Without this fix, the project will still build, but javamail will no longer work and proguard will
also fail. This is not a proguard issue at all. It is an Android SDK issue. No changes to proguard.cfg are required.
Another consequence of upgrading the SDK is that it is no longer necessary to upgrade proguard manually.
ProGuard in your project, edit project.properties,好,进入project.properties,又提到:
To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
就是把上面的#去掉,然后把sdk.dir指向你的AndroidSDK的目录,我想那个proguard-android.txt应该是个模板,是个公用的模板,每个需要混淆的工程都会用到该文件。同时,proguard-project.txt又提到Add any project specific keep options
here,即具体到某个工程需要而编写的一些特定的混淆配置,需要写在proguard-project.txt文件中,比如暴露在AndroidManifest.xml中的类,service,activity等等,加入生成APK后,运行过程中,找不到某个类,如果不是jar库没有有效编译就去,那就是混淆器把这类给混淆了,运行时无法找到这个类,需要把这个类keep,保持原样。根据经验,一般只需要keep
类即可,对变量和函数一般不需要做处理
如何输出混淆的APK,右键工程--->Android Tools--->Export Unsigned Application Package。
但是用上述方法输出的apk无法安装,提示“应用程序未安装”,后来通过右键工程--->Android Tools--->Export Signed Application Package,然后开始自己新建一个key_store,设置好用
了!!!!
问题:
I am trying to use javamail in my Android app, but proguard complains about a whole load of stuff that it cannot find. I have tried various remedies that I have found while searching the internet, but nothing seems to work. Has
anyone got this thing working? Thanks.
I have added some -dontwarn commands to the defauly proguard.cfg, and succeeded in eliminating all of the warning messages except this one:
Warning: org.apache.harmony.awt.datatransfer.DataProxy:
解决:
I am using the 2.1 SDK, which might make a difference. I also have a fairly complex email. But I have sorted it now, by upgrading to proguard 4.6 and adding the following lines to the head my proguard.cfg:
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
The last group of lines is non-trivial. I obtained it by running tar tf commands against each of the jars in the javamail package.
同时如果使用pop3接收邮件,应该加上-keep class com.sun.mail.pop3.** {*;},不然会爆出“javax.mail.nosuchproviderexception:pop3”异常,原因可能是proguard把类com.sun.mail.pop3也给混淆了,导致程序中找不到该类。
Update for SDK 17
Android SDK 17 introduces some changes in the way that jars are loaded. If you have a project that uses external jars, upgrading to SDK 17 or beyond will probably break it. To fix this, select Project > Properties > Java Build Path
> Order and Export from the menu, and check the boxes to left of the three jars used by javamail. This ensures that the jars get exported to the target build. Without this fix, the project will still build, but javamail will no longer work and proguard will
also fail. This is not a proguard issue at all. It is an Android SDK issue. No changes to proguard.cfg are required.
Another consequence of upgrading the SDK is that it is no longer necessary to upgrade proguard manually.
相关文章推荐
- Android(Java):代码混淆
- Android 混淆 以及 java代码方式实现混淆配置
- Android项目中使用javacv和javacpp的代码混淆配置
- android代码混淆报错总结:java.io.IOException: Please correct the above
- Android的JS调用Java代码或使用了Javascript相关技术,如何混淆
- android代码混淆报错总结:java.io.IOException: Please correct the above warnings first
- Android的JS调用Java代码或使用了Javascript相关技术,混淆问题
- Android(java)学习笔记128:使用proguard混淆android代码
- Android应用开发之代码混淆
- Android 开发系列(3) - native代码调用java代码出现attempt using stale local reference错误及解决办法
- Android 代码混淆
- 手游中android平台在java代码里--->游戏子线程和java主线程的交替运行
- android webView开发之js调用java代码示例
- Android 代码混淆、第三方平台加固加密、渠道分发 完整教程(转)
- Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完成测试代码)
- Android 在Java代码中设置style属性
- Android 实现代码混淆的实例
- android 代码混淆与反编译
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- Android代码混淆及项目发布步骤记录