andrei_zaitcev andrei_zaitcev - 4 years ago 247
Android Question

Google Awareness API SecurityException is thrown

I'm using DetectedActivityFence from Google Awareness API. It's working fine on my own devices, but I received a several crashes in Crashlytics about SecurityException.

Fatal Exception: java.lang.SecurityException: Invalid API Key for package = [package_name] .Status code received = -1
at android.os.Parcel.readException(
at android.os.Parcel.readException(
at$zza$zza.zza(Unknown Source)
at Source)
at$zzc.zzapl(Unknown Source)
at$ Source)
at java.util.concurrent.Executors$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
at Source)

This happened without any correlations between Android versions, i.e. it affects devices from different manufacturers and different Android versions(5.x-6.x). These devices aren't rooted and look like working on Stock ROM. This problem appears for 10% of my users.

I'm sure that I'm using the right API key otherwise I can see the crash on my own device, can I?

Did anybody face the same issue?

Answer Source

There is a bug that erroneously mistakes some errors from the network operation to authenticate the app as indicating that the API key was not set up correctly, even though the actual error was something else. This has been fixed internally and will roll out in the next Google Play services release.

For now, the best workaround is to add an UncaughtExceptionHandler on the thread that calls GoogleApiClient.connect(). If you call GoogleApiClient.connect() on the main thread, then you can get the Thread instance via Looper.myLooper().getThread().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download