Android Trick 14: proguard导致签名后的apk报错:ClassNotFoundException 的问题解决
2012-01-10 22:41
429 查看
/article/1393562.html
发布在Android Market上的apk应用需要经过签名,签名的时候如果存在proguard.cfg并且在default.properties里边启动了proguard:proguard.config=proguard.cfg,那么在签名打包时会使用proguard对代码进行压缩、优化和混淆。
在使用时遇到了一些问题,
首先,随Android SDK自带的默认的proguard4.4?,签名后的apk安装成功,但运行时报ClassNotFoundException。检查了一遍签名的过程,发现签名完成时会弹出“ conversion to dalvik format failed with error 1” 错误,查网上看到了遇到相同问题的开发,据他们说在官网下载最新版4.6后,此问题解决。于是在http://proguard.sourceforge.net/下载到最新版后,重新运行签名,发现错误没有了。
但是,新签的apk然后报ClassNotFoundException异常,最初的问题还没解,继续查。发现,在sdk文档中有相关描述:
For some situations, the default configurations in the
Some examples include:
a class that is referenced only in the
a method called from JNI
dynamically referenced fields and methods
The default
calls.
You can fix errors when ProGuard strips away your code by adding a
There are many options and considerations when using the
Manual for more information about customizing your configuration file. The Overview of Keep optionsand Examples
section are particularly helpful. The Troubleshooting section of the ProGuard Manual outlines other common problems you might encounter
when your code gets stripped away. (developer.android.com/guide/developing/tools/proguard.html)
OK! 重要知道问题原因,默认的proguard配置还是不太全面,有些类在压缩混淆的时候去掉了,这种情况碰巧这次中招了,于是按照指南,马上在proguard.cfg配置中加入一行 keep public class ...sth..., 搞定。
发布在Android Market上的apk应用需要经过签名,签名的时候如果存在proguard.cfg并且在default.properties里边启动了proguard:proguard.config=proguard.cfg,那么在签名打包时会使用proguard对代码进行压缩、优化和混淆。
在使用时遇到了一些问题,
首先,随Android SDK自带的默认的proguard4.4?,签名后的apk安装成功,但运行时报ClassNotFoundException。检查了一遍签名的过程,发现签名完成时会弹出“ conversion to dalvik format failed with error 1” 错误,查网上看到了遇到相同问题的开发,据他们说在官网下载最新版4.6后,此问题解决。于是在http://proguard.sourceforge.net/下载到最新版后,重新运行签名,发现错误没有了。
但是,新签的apk然后报ClassNotFoundException异常,最初的问题还没解,继续查。发现,在sdk文档中有相关描述:
Configuring ProGuard
For some situations, the default configurations in the proguard.cfgfile will suffice. However, many situations are hard for ProGuard to analyze correctly and it might remove code that it thinks is not used, but your application actually needs.
Some examples include:
a class that is referenced only in the
AndroidManifest.xmlfile
a method called from JNI
dynamically referenced fields and methods
The default
proguard.cfgfile tries to cover general cases, but you might encounter exceptions such as
ClassNotFoundException, which happens when ProGuard strips away an entire class that your application
calls.
You can fix errors when ProGuard strips away your code by adding a
-keepline in the
proguard.cfgfile. For example:
-keep public class <MyClass>
There are many options and considerations when using the
-keepoption, so it is highly recommended that you read the ProGuard
Manual for more information about customizing your configuration file. The Overview of Keep optionsand Examples
section are particularly helpful. The Troubleshooting section of the ProGuard Manual outlines other common problems you might encounter
when your code gets stripped away. (developer.android.com/guide/developing/tools/proguard.html)
OK! 重要知道问题原因,默认的proguard配置还是不太全面,有些类在压缩混淆的时候去掉了,这种情况碰巧这次中招了,于是按照指南,马上在proguard.cfg配置中加入一行 keep public class ...sth..., 搞定。
相关文章推荐
- java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver问题解决
- ClassNotFoundException问题解决
- 解决使用libhdfs.so连接hdfs出错问题java.lang.ClassNotFoundException: org.apache.hadoop.fs.F
- java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener问题解决
- 解决Eclipse中运行WordCount出现 java.lang.ClassNotFoundException: org.apache.hadoop.examples.WordCount$TokenizerMapper问题【转】
- 解决java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver问题
- 【解决】SSH问题(三)java.lang.ClassNotFoundException: org.quartz.impl.triggers.SimpleTriggerImpl
- WTP/JSF问题的解决--java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
- java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener问题解决
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL问题解决方法
- 解决SSM,java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener 问题
- 关于android项目中在eclipse里引入新jar导致新jar中的class not found Exception的解决
- 第91课:SparkStreaming基于Kafka Direct案例实战和内幕源码解密 java.lang.ClassNotFoundException 踩坑解决问题详细内幕版本
- FacesServlet (Java EEWTP/JSF问题的解决--java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
- 解决 java.lang.ClassNotFoundException配置文件出错的问题
- Android 开发中ClassNotFoundException的问题原因和解决方法
- java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener问题解决
- 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.Contex
- 解决maven工程下java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts问题
- 【解决】SSH问题(四)Java.Lang.ClassNotFoundException: Org.Springframework.Transaction.TransactionException