简体   繁体   English

引发Google Awareness API SecurityException

[英]Google Awareness API SecurityException is thrown

I'm using DetectedActivityFence from Google Awareness API . 我正在使用Google Awareness API中的 DetectedActivityFence It's working fine on my own devices, but I received a several crashes in Crashlytics about SecurityException . 它在我自己的设备上工作正常,但我在Crashlytics中收到了几起关于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, ie it affects devices from different manufacturers and different Android versions(5.x-6.x). 这种情况在Android版本之间没有任何相关性,即它影响来自不同制造商和不同Android版本(5.x-6.x)的设备。 These devices aren't rooted and look like working on Stock ROM. 这些设备没有root,看起来像在Stock ROM上工作。 This problem appears for 10% of my users. 10%的用户会出现此问题。

I'm sure that I'm using the right API key otherwise I can see the crash on my own device, can I? 我确定我使用的是正确的API密钥,否则我可以在自己的设备上看到崩溃,是吗?

Did anybody face the same issue? 有没有人面临同样的问题?

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. 有一个错误错误地将网络操作中的一些错误错误地认证为应用程序,因为表明API密钥未正确设置,即使实际错误是其他错误。 This has been fixed internally and will roll out in the next Google Play services release. 这已在内部修复,并将在下一个Google Play服务版本中推出。

For now, the best workaround is to add an UncaughtExceptionHandler on the thread that calls GoogleApiClient.connect(). 目前,最好的解决方法是在调用GoogleApiClient.connect()的线程上添加UncaughtExceptionHandler。 If you call GoogleApiClient.connect() on the main thread, then you can get the Thread instance via Looper.myLooper().getThread(). 如果在主线程上调用GoogleApiClient.connect(),则可以通过Looper.myLooper()。getThread()获取Thread实例。

From: https://code.google.com/p/android/issues/detail?id=223751#c2 来自: 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. 我们的检查中存在一个错误,当有网络错误进行身份验证时,有时会抛出此SecurityException。 The fix will rollout in the next version of Google Play services. 该修补程序将在下一版Google Play服务中推出。

For now, the best workaround would be set up an UncaughtExceptionHandler on the thread that you call GoogleApiClient.connect(). 目前,最好的解决方法是在您调用GoogleApiClient.connect()的线程上设置UncaughtExceptionHandler。 For most folks, this would be on the main thread, which you can get via Looper.myLooper().getThread(). 对于大多数人来说,这将在主线程上,您可以通过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. 您可能还会注意到该线程的OP引用了此SO帖子,但是接受的答案不会引用该线程,即使它们是逐字复制的。 Very bad form! 非常糟糕的形式!

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. 我遇到了这个问题,因为我遇到了同样的错误,我认为可能是Awareness API密钥未同步到Google Developer Console,经过大量查看并收到相同的错误后,我又回到了Google上的Awareness API开发者控制台并实现我的Awareness API没有启用,即使我有包装并拥有有效的API密钥。 Also make sure that API key is set in your Manifest. 还要确保在Manifest中设置了API密钥。 Hope this helps someone. 希望这有助于某人。

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. 我唯一能帮助我在Google Developer Console上使用调试密钥库生成API密钥以进行测试,并在投入生产时将其替换为发布密钥库。

How generate API key? 如何生成API密钥? Please check out Google's word itself Here 在这里查看谷歌的单词

Hope it will help someone in future. 希望它将来有助于某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM