Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal Exception: java.lang.NoSuchMethodError in com.google.android.gms.common.api.internal.BackgroundDetector.readCurrentStateIfPossible

I got lots of this on Android 4.0.4 where android.app.ActivityManager.getMyMemoryState is missing method.

And full stack trace is:

Fatal Exception: java.lang.NoSuchMethodError: android.app.ActivityManager.getMyMemoryState
       at com.google.android.gms.common.api.internal.BackgroundDetector.readCurrentStateIfPossible(Unknown Source:17)
       at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(Unknown Source:169)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at com.google.android.gms.internal.base.zap.dispatchMessage(Unknown Source:8)
       at android.os.Looper.loop(Looper.java:154)
       at android.os.HandlerThread.run(HandlerThread.java:65

My gms related dependencies is:

implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-games:16.0.0'

+ firebase:

implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-perf:16.2.3'
implementation 'com.google.firebase:firebase-ads:17.1.3'

Which seem to be up to date (at time of writing)

Is there anything I can do to prevent those crashes?

like image 288
Mike666 Avatar asked Mar 03 '19 21:03

Mike666


2 Answers

I located the source of this issue:

play-services-base:16.1.0 assume it runs on at least JellyBean (API level 16) OS (I found this with help of Android Studio java decompiler (PlatformVersion.isAtLeastJellyBean just unconditionally return true.)), which, is not true in my case.

So I downgraded to play-services-base:16.1.0 to play-services-base:16.0.1 and crashes was stopped.

like image 157
Mike666 Avatar answered Sep 18 '22 07:09

Mike666


Until the problem is not solved by Google, just use and force play-services-basement:16.0.1

implementation "com.google.android.gms:play-services-basement:16.0.1"

configurations.all {
    resolutionStrategy.force "com.google.android.gms:play-services-basement:16.0.1"
}
like image 23
braintrapp Avatar answered Sep 22 '22 07:09

braintrapp