Proguard crashes on google play services. ActivityRecognitionResult getMostProbableActivity

I recently released the app in a game store, and although it works fine without proguard, I had an unexpected accident when I decided to use it.

I looked here for recommended security rules for google play services, I also tried to add another line for this case. Here is what I got (third line for my application):

-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 a crash report after doing a reverse

 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) 

Offensive lines of code are probably the following:

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

Can someone help with adding a rule? I do not want to disconnect all this together, but it fixes a problem.

+4
source share
2 answers

Android runtime accesses these CREATOR fields using reflection, which, as a rule, cannot be detected using static analysis. Therefore, you must tell ProGuard to save them:

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

This is not like the standard setting in android-sdk/tools/proguard/proguard-android.txt , but it probably should be.

+13
source

This problem drove me crazy. Proguard robs inner classes that are not explicitly imported. Worse, this problem did not exist for me (after using Proguard), then one day it suddenly appeared after several small code changes.

I added a couple of Proguard flags to fix this problem. In the end, I'm 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 

up

Honestly, a problem like dependencies and Proguard should be better than this, but I eventually fixed it as stated above.

+1
source

Source: https://habr.com/ru/post/1500481/


All Articles