【发布时间】:2018-04-08 22:25:14
【问题描述】:
Google 作为教程提供的实际示例 Google Android Studio Project CurrentPlaceDetailsOnMap 似乎在带有 API 19 和 Google API 的 android 4.4.2 AVD 中崩溃。
任何人都可以自己直接测试。在您第一次在当前的 Android Studio 3.1 中打开项目后,它会为您提供一个 Android Gradle 插件更新推荐对话框,然后我运行该更新。接下来,它给了我一堆配置“编译”已过时,并已替换为实现错误,我通过替换引用来修复这些错误。然后我用我在谷歌注册后收到的密钥替换了 gradle.properties 文件中的 GOOGLE_MAPS_API_KEY。然后我构建并运行应用程序,该应用程序随后因“不幸的是,当前地点详细信息已停止。”错误而崩溃。注意:该应用程序在我的 4.4 设备上运行,但在 AVD 中不起作用。
我没有对原始教程代码进行修改,除了将编译更改为实现并添加我的谷歌 api 密钥。我注意到如果我有它跳过这一行:
mapFragment.getMapAsync(this);
然后它运行,但没有放大到正确的位置。我不明白 logcat 跟踪的输出,但也许它有助于调试问题。 有什么建议可以在不崩溃的情况下继续在 AVD 中进行测试吗?谢谢。
更新:我大致尝试跟踪堆栈跟踪,看起来 AVD 在第 212 行崩溃:
new LatLng(mLastKnownLocation.getLatitude(),
这里是 logcat 控制台的下 1/2:
04-08 22:50:57.911 4820-4820/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x005d
04-08 22:50:57.911 4820-4820/com.example.currentplacedetailsonmap I/dalvikvm: Could not find method android.content.Context.isDeviceProtectedStorage, referenced from method tm.a
04-08 22:50:57.911 4820-4820/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve virtual method 683: Landroid/content/Context;.isDeviceProtectedStorage ()Z
04-08 22:50:57.911 4820-4820/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x0009
04-08 22:50:57.921 4820-4820/com.example.currentplacedetailsonmap D/dalvikvm: GC_FOR_ALLOC freed 373K, 13% free 3258K/3740K, paused 2ms, total 2ms
04-08 22:50:57.921 4820-4820/com.example.currentplacedetailsonmap D/dalvikvm: GC_FOR_ALLOC freed 9K, 13% free 3316K/3796K, paused 1ms, total 1ms
GC_FOR_ALLOC freed 1K, 13% free 3413K/3896K, paused 1ms, total 1ms
04-08 22:50:57.921 4820-4820/com.example.currentplacedetailsonmap I/dalvikvm-heap: Grow heap (frag case) to 4.512MB for 1127532-byte allocation
04-08 22:50:57.931 4820-4829/com.example.currentplacedetailsonmap D/dalvikvm: GC_FOR_ALLOC freed <1K, 10% free 4514K/5000K, paused 3ms, total 3ms
04-08 22:50:57.941 4820-4820/com.example.currentplacedetailsonmap D/dalvikvm: GC_FOR_ALLOC freed 43K, 9% free 4711K/5168K, paused 2ms, total 2ms
04-08 22:50:57.941 4820-4820/com.example.currentplacedetailsonmap W/ContextImpl: Failed to ensure directory: /storage/sdcard/Android/data/com.example.currentplacedetailsonmap/cache
04-08 22:50:57.951 4820-4840/com.example.currentplacedetailsonmap I/dalvikvm: Could not find method android.os.PowerManager.isInteractive, referenced from method om.a
04-08 22:50:57.951 4820-4840/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve virtual method 1094: Landroid/os/PowerManager;.isInteractive ()Z
04-08 22:50:57.951 4820-4840/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x003b
04-08 22:50:57.951 4820-4840/com.example.currentplacedetailsonmap W/ActivityThread: ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
04-08 22:50:57.961 4820-4820/com.example.currentplacedetailsonmap D/dalvikvm: GC_FOR_ALLOC freed 352K, 9% free 4992K/5452K, paused 1ms, total 2ms
04-08 22:50:58.001 4820-4820/com.example.currentplacedetailsonmap D/EGL_emulation: eglCreateContext: 0xb7978e70: maj 2 min 0 rcv 2
04-08 22:50:58.021 4820-4820/com.example.currentplacedetailsonmap D/EGL_emulation: eglMakeCurrent: 0xb7978e70: ver 2 0
04-08 22:50:58.021 4820-4820/com.example.currentplacedetailsonmap E/EGL_emulation: tid 4820: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)
04-08 22:50:58.021 4820-4820/com.example.currentplacedetailsonmap W/HardwareRenderer: Backbuffer cannot be preserved
04-08 22:50:58.021 4820-4820/com.example.currentplacedetailsonmap D/OpenGLRenderer: Enabling debug mode 0
04-08 22:50:58.031 4820-4840/com.example.currentplacedetailsonmap D/dalvikvm: GC_FOR_ALLOC freed 486K, 11% free 5225K/5820K, paused 2ms, total 2ms
04-08 22:50:58.041 4820-4820/com.example.currentplacedetailsonmap D/AndroidRuntime: Shutting down VM
04-08 22:50:58.041 4820-4820/com.example.currentplacedetailsonmap W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d25b20)
04-08 22:50:58.041 4820-4820/com.example.currentplacedetailsonmap E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.currentplacedetailsonmap, PID: 4820
java.lang.NullPointerException
at com.example.currentplacedetailsonmap.MapsActivityCurrentPlace$2.onComplete(MapsActivityCurrentPlace.java:212)
at com.google.android.gms.tasks.zzf.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
Selected remote version of com.google.android.gms.googlecertificates, version >= 4
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap I/dalvikvm: Could not find method android.content.ContextWrapper.createCredentialProtectedStorageContext, referenced from method ar.createCredentialProtectedStorageContext
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve virtual method 102: Landroid/content/ContextWrapper;.createCredentialProtectedStorageContext ()Landroid/content/Context;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap I/dalvikvm: Could not find method android.content.ContextWrapper.createDeviceProtectedStorageContext, referenced from method ar.createDeviceProtectedStorageContext
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve virtual method 103: Landroid/content/ContextWrapper;.createDeviceProtectedStorageContext ()Landroid/content/Context;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap I/dalvikvm: Could not find method o.createCredentialProtectedStorageContext, referenced from method p.createCredentialProtectedStorageContext
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve virtual method 725: Lo;.createCredentialProtectedStorageContext ()Landroid/content/Context;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap I/dalvikvm: Could not find method o.createDeviceProtectedStorageContext, referenced from method p.createDeviceProtectedStorageContext
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve virtual method 726: Lo;.createDeviceProtectedStorageContext ()Landroid/content/Context;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve static field 58 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0012
DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_32_BIT_ABIS
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve static field 57 (SUPPORTED_32_BIT_ABIS) in Landroid/os/Build;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0021
DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap W/dalvikvm: VFY: unable to resolve static field 58 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build;
04-08 22:50:59.971 4820-4866/com.example.currentplacedetailsonmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0008
【问题讨论】:
-
得到了上面介绍段落中提到的密钥。它在我的 4.4 android 设备上运行,但在 AVD 中不起作用。不过感谢您的提示。
-
@Andy 对此感到抱歉。实际上,我在更换密钥之前粘贴了我的第一个 logcat。我想知道您是如何知道我最初没有替换密钥的,直到我在原始发布的 logcat 中看到它。我修复了我的 logcat,因为它现在显示。它仍然不能在 4.4.2 AVD 上运行,但只能在我的设备上运行。这对我来说并不总是可用,所以我需要它在 AVD 上工作。
标签: android google-maps fatal-error