【问题标题】:Google Maps Sample project builds but stops on Android 4.4.2 w Google API'sGoogle Maps Sample 项目在使用 Google API 的 Android 4.4.2 上构建但停止
【发布时间】: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

【问题讨论】:

  • 要解决“授权失败”,请参阅:developers.google.com/maps/documentation/android-api/signup
  • 得到了上面介绍段落中提到的密钥。它在我的 4.4 android 设备上运行,但在 AVD 中不起作用。不过感谢您的提示。
  • @Andy 对此感到抱歉。实际上,我在更换密钥之前粘贴了我的第一个 logcat。我想知道您是如何知道我最初没有替换密钥的,直到我在原始发布的 logcat 中看到它。我修复了我的 logcat,因为它现在显示。它仍然不能在 4.4.2 AVD 上运行,但只能在我的设备上运行。这对我来说并不总是可用,所以我需要它在 AVD 上工作。

标签: android google-maps fatal-error


【解决方案1】:

到目前为止,从堆栈跟踪来看,它似乎由于 mLastKnownLocation 中的空值而崩溃。

我在原始的 Google 地图教程 MapsActivityCurrentPlace.java 文件中添加了一行:

if(mLastKnownLocation == null) { return; }

上面

  mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
  new LatLng(mLastKnownLocation.getLatitude(),
  mLastKnownLocation.getLongitude()), DEFAULT_ZOOM));

如果没有 mLastKnownLocation,则返回地图而不放大。

当您点击地图十字准线时,您将获得更新的位置。

有趣的是,4.4.2 AVD 从未存储过导致其崩溃的先前位置(可能在缓存中)。我没有在 AVD 上尝试过不同版本的 API,我猜测它可能会在其他版本上崩溃。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 2014-04-23
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多