Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proguard causes a crash in google play services' ActivityRecognitionResult getMostProbableActivity

I've recently released an app to the play store, and while it works perfectly fine without proguard, i've got an unexpected crash when i did decide to use it.

I've looked here for the recommended proguard rules for google play services, i've also tried adding another line for this case. Here's what I got (the third line is for my app):

-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

Here's the crash report after doing a retrace

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)

The offending lines of code probably are:

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

Can anyone help out with a rule to add? I don't want to disable it all together but it does fix the issue.

like image 458
Anton Wolkov Avatar asked Dec 09 '22 13:12

Anton Wolkov


1 Answers

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.

like image 197
Eric Lafortune Avatar answered May 20 '23 22:05

Eric Lafortune