Android Trick 14： proguard导致签名后的apk报错：ClassNotFoundException 的问题解决

Configuring ProGuard

For some situations, the default configurations in the proguard.cfg file 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.xml file
• a method called from JNI
• dynamically referenced fields and methods

The default proguard.cfg file 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 -keep line in the proguard.cfg file. For example:

-keep public class <MyClass>

There are many options and considerations when using the -keep option, so it is highly recommended that you read the ProGuard Manual for more information about customizing your configuration file. The Overview of Keep options and 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..., 搞定。

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客