proguard causes a crash in google play services' ActivityRecognitionResult getMostProbableActivity

◇◆丶佛笑我妖孽 提交于 2019-12-05 17:53:09

The Android runtime accesses these CREATOR fields by means of reflection, which is generally impossible to detect using static analysis. You therefore need to tell ProGuard to preserve them:

-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}

This doesn't seem to be a standard setting in android-sdk/tools/proguard/proguard-android.txt, but it probably should be.

This problem drove me insane. Proguard is stripping internal classes that are not explicitly imported. Even worse, this problem did not exist for me (after using Proguard) then one day is suddenly showed up after a few little code changes.

I added a swathe of Proguard flags to fix the issue. In the end, I am not sure which one did the trick:

Definitely add these three:

-keep class android.os.Parcelable.Creator
-keep class com.google.android.gms.location.ActivityRecognitionResult
-keep class com.google.android.gms.** {*;}

You can also try:

-dontshrink
-dontoptimize

at the top

Honestly it's a dependency-walker type problem and Proguard should be better than this, but I did eventually fix it as above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!