proguard 导致 Google Play 服务的 ActivityRecognitionResult getMostProbableActivity 崩溃

2024-05-24

我最近向 Play 商店发布了一个应用程序,虽然它在没有 proguard 的情况下运行得很好,但当我决定使用它时,我遇到了意外的崩溃。

我看过here http://developer.android.com/google/play-services/setup.html#Setup对于谷歌播放服务推荐的混淆器规则,我还尝试为此案例添加另一行。这是我得到的(第三行是我的应用程序):

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}
-keep class * implements com.google.android.gms.internal.ae
-keep class * extends il.co.kix.minitasker.EntityBase

这是回溯后的崩溃报告

android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class com.google.android.gms.location.ActivityRecognitionResult
at android.os.Parcel.readParcelable(Parcel.java:2086)
at android.os.Parcel.readValue(Parcel.java:1965)
at android.os.Parcel.readMapInternal(Parcel.java:2226)
at android.os.Bundle.unparcel(Bundle.java:223)
at android.os.Bundle.containsKey(Bundle.java:271)
at android.content.Intent.hasExtra(Intent.java:4116)
at com.google.android.gms.location.ActivityRecognitionResult.boolean hasResult(android.content.Intent)(Unknown Source)
                                                             com.google.android.gms.location.DetectedActivity getMostProbableActivity()
at il.co.kix.minitasker.ActivityRecognitionIntentService.void onHandleIntent(android.content.Intent)(Unknown Source)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)

有问题的代码行可能是:

...
   @Override
    protected void onHandleIntent(Intent intent) {
        if (ActivityRecognitionResult.hasResult(intent)) {
            ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
            DetectedActivity mostProbableActivity = result.getMostProbableActivity();
...

谁能帮忙添加一条规则吗?我不想将其全部禁用,但它确实解决了问题。


Android运行时通过反射的方式访问这些CREATOR字段,这通常无法使用静态分析来检测。因此,您需要告诉 ProGuard 保留它们:

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

这似乎不是标准设置android-sdk/tools/proguard/proguard-android.txt,但也许应该是这样。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

proguard 导致 Google Play 服务的 ActivityRecognitionResult getMostProbableActivity 崩溃 的相关文章

随机推荐