Playing release
pack when it came to this issue, it is relatively common, remember this 解决思路
.
This article introduces the reasons for this problem, as well as when 我的建议
and when the problem occurs 我的思路
, you can directly look at it if you are anxious 解决方案
.
abnormal
Subscriber class xxx and its super classes have no public methods with the @Subscribe annotation
Don't panic when you encounter an exception. In fact, the prompt is obvious. The specific is specified class
, and it is clearly told that this class has no @Subscribe
annotations.
the reason
But in fact, after knowing the problem, there may still be doubts, such as me, because my class is @Subscribe
annotated, so why?
Knowing the specific class
, but also know @Subscribe
notes, so it is easy to locate to being EventBus
.
Then go to EventBus
the official website to find the answer, and she issues
had the same problem on the first page, the author team of such a reply:
Check your R8 / ProGuard rules.
https://github.com/greenrobot/EventBus#r8-proguard
Check your compression/obfuscation rules.
Only then did I realize that it was R8
caused by turning on compression,minifyEnabled true
buildTypes {
release {
minifyEnabled true
...
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Then why the R8
above exception will be caused when compression is turned on , because EventBus
the annotation uses reflection.
Reflection will cause R8 to fail to recognize the entry point of the code when tracking the code. Third-party libraries may also use reflection, and since third-party libraries are actually part of your application, you (as the application developer) will be responsible for reflection used in these libraries and your own code. Third-party libraries may come with their own rules, but keep in mind that some libraries are not necessarily written for Android, or reduction issues are not considered, so they may require additional configuration.
solution
After understanding the cause and effect, the solution should be born.
Option One
Turn off R8
compression
minifyEnabled false
But this will increase your application a lot. For example, when you use a third-party library, only a small part of it is used in the application, but all library code will remain in the application when packaging.
If you don't mind, this is the best 简单粗暴
solution.
Author: https: //blog.csdn.net/yechaoa
Option II
Add corresponding 压缩/混淆
rules, such as EventBus
:
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode {
*; }
# And if you use AsyncExecutor:
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
to sum up
In fact, the problem is not complicated. The key is the process of solving the problem. I want to convey the following points:
- Don’t panic when you encounter a problem, and don’t blindly search for the answer. This will waste time and may confuse your sight
- Look at it carefully
日志
, the general log will give you a hint - Combine all available information to locate problems quickly and accurately
- If you have to search, it is recommended to
官方文档
find the answer first
How did I solve this exception:
- According to the log prompt, I located the problem
EventBus
- Check the tutorial, and found no problems
- Check the EventBus
issues
to see if there is the same problem, it is true, and I know theR8压缩
cause - Go to
google官网
check theR8
relevant introduction, know the reason, and provide a solution
By analogy, other questions also apply.
If it is useful or enlightening to you, please give me a thumbs up ^ _ ^