Android解决混淆后注解空指针问题


未混淆的代码为

 混淆之后:

 可以看到混淆打包之后注解全都被去掉了!!!

解决方式为添加以下混淆文件

# mvp注解框架混淆
-keep @com.example.httplibrary.mvp.inject.InjectPresenter class * {*;}
-keepclasseswithmembers class * {
    @com.example.httplibrary.mvp.inject.InjectPresenter ;
}
-keepclasseswithmembers class * {
    @com.example.httplibrary.mvp.inject.InjectPresenter ;
}
-keepclasseswithmembers class * {
    @com.example.httplibrary.mvp.inject.InjectPresenter (...);
}
# The "Signature" attribute is required to be able to access generic types whencompiling in JDK 5.0 and higher.
-keepattributes Signature
# processing Annotations
-keepattributes *Annotation*

加入混淆文件之后,运行正常,加入混淆文件之后代码如下: