【问题标题】:How to use Google Maps API v2 with API level 10?如何在 API 级别 10 中使用 Google Maps API v2?
【发布时间】:2014-06-28 22:29:00
【问题描述】:

根据1 发布的代码可用于Android API 12 或更高版本。我在具有 API 级别 10(Google API 平台 2.3.3)的模拟器上尝试了代码,并收到以下著名错误:

E/AndroidRuntime( 429): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example..../com.example....MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

我在下面复制粘贴我的 .xml 文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.MapFragment"/>

所以我假设不支持片段元素...(?)。我在 API 级别 17 的模拟器中尝试了相同的代码,我收到了这条消息(我正在阅读,目前是模拟器的问题):

This app won't run unless you update Google Play Services.

我没有真正的 17 级设备来测试它,但我认为它可能会工作。

我在上面的代码中是否有任何错误,专门针对 10 级? Google 目前支持的代码是什么,以便在 API 级别 10 的 Android 设备中开发地图?

1https://developers.google.com/maps/documentation/android/start

更新: 更改为FragmentActivitySupportMapFragment 后,我得到以下信息:

W/dalvikvm( 6718): Unable to resolve superclass of Lmaps/a/du; (406)
W/dalvikvm( 6718): Link of class 'Lmaps/a/du;' failed
W/dalvikvm( 6718): Unable to resolve superclass of Lmaps/a/ej; (2358)
W/dalvikvm( 6718): Link of class 'Lmaps/a/ej;' failed
W/dalvikvm( 6718): Unable to resolve superclass of Lmaps/j/k; (2374)
W/dalvikvm( 6718): Link of class 'Lmaps/j/k;' failed
E/dalvikvm( 6718): Could not find class 'maps.j.k', referenced from method maps. y.ae.a
W/dalvikvm( 6718): VFY: unable to resolve new-instance 3566 (Lmaps/j/k;) in Lmap s/y/ae;
D/dalvikvm( 6718): VFY: replacing opcode 0x22 at 0x007d
D/dalvikvm( 6718): VFY: dead code 0x007f-008f in Lmaps/y/ae;.a(Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;Z)Lmaps/y/ae;

2 秒后:
Google Maps Android API Authorization failure

更新 2: 我将项目更改为为 android 10 构建目标(我为 android 4.2 提供了它)。所以现在我没有看到授权失败)。我还粘贴了来自 google 的 api 访问。

我没有在项目的 .properties 中启用 proguard,即:
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-10
android.library.reference.1=../../adt-bundle-windows-x86/sdk/extras/google/google_play_services/libproject/google-play-services_lib

问题依旧:

01-12 09:57:36.306: D/dalvikvm(9072): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
01-12 09:57:36.306: W/dalvikvm(9072): VFY: unable to resolve instance field 24
01-12 09:57:36.306: D/dalvikvm(9072): VFY: replacing opcode 0x52 at 0x0012
01-12 09:57:36.306: D/dalvikvm(9072): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
01-12 09:57:36.326: W/dalvikvm(1914): disableGcForExternalAlloc: false
01-12 09:57:36.446: D/dalvikvm(9072): GC_CONCURRENT freed 186K, 45% free 3135K/5639K, external 0K/0K, paused 3ms+2ms
01-12 09:57:36.476: W/dalvikvm(9072): Unable to resolve superclass of Lmaps/a/du; (406)
01-12 09:57:36.476: W/ResourceType(7905): getEntry failing because entryIndex 303 is beyond type entryCount 133
01-12 09:57:36.476: W/ResourceType(7905): Failure getting entry for 0x7f02012f (t=1 e=303) in package 0 (error -2147483647)
01-12 09:57:36.476: W/ResourceType(7905): getEntry failing because entryIndex 827 is beyond type entryCount 133
01-12 09:57:36.476: W/dalvikvm(9072): Link of class 'Lmaps/a/du;' failed
01-12 09:57:36.476: W/dalvikvm(9072): Unable to resolve superclass of Lmaps/a/ej; (2358)
01-12 09:57:36.476: W/dalvikvm(9072): Link of class 'Lmaps/a/ej;' failed
01-12 09:57:36.476: W/dalvikvm(9072): Unable to resolve superclass of Lmaps/j/k; (2374)
01-12 09:57:36.476: W/dalvikvm(9072): Link of class 'Lmaps/j/k;' failed
01-12 09:57:36.486: E/dalvikvm(9072): Could not find class 'maps.j.k', referenced from method maps.y.ae.a
@ 987654362@
01-12 09:57:36.486: D/dalvikvm(9072): VFY: replacing opcode 0x22 at 0x007d
01-12 09:57:36.496: D/dalvikvm(9072): VFY: dead code 0x007f-008f in Lmaps/y/ae;.a (Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;Z)Lmaps/y/ae;
01-12 09:57:36.546: I/keystore(1270): uid: 1000 action: e -&gt; 7 state: 3 -&gt; 3 retry: 4
01-12 09:57:36.556: I/keystore(1270): uid: 1000 action: e -&gt; 7 state: 3 -&gt; 3 retry: 4
&lt;01-12 09:57:36.576: W/ResourceType(7905): Failure getting entry for 0x7f02033b (t=1 e=827) in package 0 (error -2147483647)
01-12 09:57:36.576: V/WindowManager(1369): Finished animation in AppWindowToken{410a0930 token=HistoryRecord{4099f2f0 com.example..../.MainActivity}} @ 20019326
01-12 09:57:36.596: W/ResourceType(7905): getEntry failing because entryIndex 303 is beyond type entryCount 133
01-12 09:57:36.616: W/ResourceType(7905): Failure getting entry for 0x7f02012f (t=1 e=303) in package 0 (error -2147483647)
01-12 09:57:36.616: W/ResourceType(7905): getEntry failing because entryIndex 827 is beyond type entryCount 133
01-12 09:57:36.616: W/ResourceType(7905): Failure getting entry for 0x7f02033b (t=1 e=827) in package 0 (error -2147483647)
01-12 09:57:36.686: D/dalvikvm(9072): GC_CONCURRENT freed 276K, 45% free 3257K/5895K, external 0K/0K, paused 4ms+9ms
01-12 09:57:36.876: I/keystore(1270): uid: 1000 action: e -&gt; 7 state: 3 -&gt; 3 retry: 4
01-12 09:57:37.026: D/ATRecorder(9072): com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@405d2328
01-12 09:57:37.046: D/WindowManagerImpl(9072): addView, new view, mViews[0]: com.android.internal.policy.impl.PhoneWindow$DecorView@405220f0
01-12 09:57:37.056: I/keystore(1270): uid: 1000 action: e -&gt; 7 state: 3 -&gt; 3 retry: 4
01-12 09:57:37.117: D/PhoneApp(1491): EVENT_QUERY_MO_PACKAGES
01-12 09:57:37.137: D/libEGL(9072): loaded /system/lib/egl/libGLES_android.so
01-12 09:57:37.147: D/WindowManagerImpl(1369): finishRemoveViewLocked, mViews[1]: com.android.internal.policy.impl.PhoneWindow$DecorView@40957078
01-12 09:57:37.147: I/ActivityManager(1369): Displayed com.example..../.MainActivity: +931ms
01-12 09:57:37.147: W/SchedPolicy(9072): add_tid_to_cgroup failed to write '' (Invalid argument); background=0
01-12 09:57:37.157: D/libEGL(9072): loaded /system/lib/egl/libEGL_adreno200.so
01-12 09:57:37.157: W/InputManagerService(1369): [unbindCurrentClientLocked] Disable input method client.
01-12 09:57:37.157: W/InputManagerService(1369): [startInputLocked] Enable input method client.
01-12 09:57:37.187: D/libEGL(9072): loaded /system/lib/egl/libGLESv1_CM_adreno200.so

【问题讨论】:

  • 我有同样的问题“找不到类 'maps.j.k',从方法 maps.y.ae.a 引用”我在 Nexus One 版本 2.3.6 上运行我尝试了以下方法: 1. 确保我的控制台选择了 Android Maps Api V2 2. 重新创建了我的 API 密钥(我没有收到授权错误) 3. 将我的目标更改为 Google API 4.2 4. 使用了 SupportMapFragment和 FragmentActivity 5. 根据提供的示例代码检查我的清单条目 6. 检查是否包含 google play 服务库 7. 更新了 google maps 和我设备上的 google play 我不确定还有什么可以尝试的。

标签: android google-maps


【解决方案1】:

不要使用com.google.android.gms.maps.MapFragment,而是使用com.google.android.gms.maps.SupportMapFragment,对于Activity,它必须切换为FragmentActivity,如下面评论中所述

【讨论】:

  • 另外,使用FragmentActivity 而不是Activity
  • 好的,但现在我在真实设备上遇到了这个错误:Could not find class maps.j.k, referenced from method maps.y.ae.a
  • 你能提交完整的堆栈跟踪吗?
  • 确保您的构建目标是 Google API 目标。
  • 从错误 Google Maps Android API Authorization failure did you create your authorization code throught API Console ?
【解决方案2】:

我使用下面的代码希望对你有用:-

打包和扩展

import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class UserLocation extends FragmentActivity 

代码

    android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
    SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager
            .findFragmentById(R.id.map);
    googleMap = mapFragment.getMap();

为我工作。

SupportMapFragment

http://developer.android.com/reference/com/google/android/gms/maps/SupportMapFragment.html

【讨论】:

  • 嗨,这是什么“SupportMapFragment”,我的 Eclipse 中没有得到它?
【解决方案3】:

对于早期的 API,您需要使用 SupportmapFragment。见SupportMapFragment docs,基本上用class="com.google.android.gms.maps.SupportMapFragment"代替class="com.google.android.gms.maps.MapFragment"

【讨论】:

    【解决方案4】:

    { 将此用作代码的参考.. http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/

    同样在上面的例子中,必须在清单的元数据标签中使用他自己的 Api Key 给出了生成 Api 密钥的说明 }

    现在如果您想在 android 2.3 中实现此代码


    1)首先更改Manifest

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="17" />
    

    然后右键单击>属性>Android>Android 2.3


    2)有两个google play服务库

       a)..\sdk\extras\google\google_play_services_froyo\libproject\google-play-services_lib
    
       b)..\sdk\extras\google\google_play_services\libproject\google-play-services_lib
    

    如果您正在使用 android 2.3 尝试将第一个 a 作为库项目 (您首先需要将其作为库项目导入 File>import>................)


    3)然后按照指示here


    4) 确保您的 Google Play 服务应用在您的设备上是最新的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-15
      • 1970-01-01
      • 2016-04-07
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      相关资源
      最近更新 更多