Google Awareness API SecurityException is thrown

那年仲夏 提交于 2019-12-20 11:08:38

问题


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(Parcel.java:1540)
   at android.os.Parcel.readException(Parcel.java:1493)
   at com.google.android.gms.common.internal.zzu$zza$zza.zza(Unknown Source)
   at com.google.android.gms.common.internal.zzd.zzqz(Unknown Source)
   at com.google.android.gms.internal.zzpw$zzc.zzapl(Unknown Source)
   at com.google.android.gms.internal.zzpw$zzf.run(Unknown Source)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at com.google.android.gms.internal.zzrn.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:818)

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?


回答1:


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().




回答2:


From: https://code.google.com/p/android/issues/detail?id=223751#c2

There is a bug in our checks that is sometimes throwing this SecurityException when there is a network error to authenticate. The fix will rollout in the next version of Google Play services.

For now, the best workaround would be set up an UncaughtExceptionHandler on the thread that you call GoogleApiClient.connect(). For most folks, this would be on the main thread, which you can get via Looper.myLooper().getThread().

But you will also notice that replies indicate that is not a solid work around.

You may also notice that the OP of that thread references this SO post, but the accepted answer doesn't back reference the thread, even though they copied from it verbatim. Very bad form!




回答3:


I came across this issue as i was getting the same error, and i thought it might be the Awareness API keys not syncing to the Google Developer Console, after lots of looking and getting the same error, I went back to the Awareness API on Google Developer Console and realized my Awareness API was not enabled even though, I had the package set and had a valid API key. Also make sure that API key is set in your Manifest. Hope this helps someone.




回答4:


I struggled almost a day and found another answer. Although accepted answer was correct at that time.

The only thing helped me that is generating API key on Google Developer Console using debug keystore for testing purpose and replacing same with release keystore while going to production.

How generate API key? Please check out Google's word itself Here

Hope it will help someone in future.



来源:https://stackoverflow.com/questions/39390557/google-awareness-api-securityexception-is-thrown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!