运行Android Google Maps API V2时出错

时间:2013-12-11 04:52:10

标签: android google-maps google-maps-api-2

以前,我用谷歌地图android v1,我更新到v2,我无法显示地图。并收到力量关闭错误。请帮帮我!

我的代码: 的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="lvs.android.map"
      android:versionCode="1"
      android:versionName="1.0">
<uses-sdk android:minSdkVersion="15"/>

<permission
        android:name="lvs.android.map.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

<uses-permission android:name="lvs.android.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
    <activity android:name="MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="XXXXXXXXXXXXXXXXXXXXXXX" />
</application>

logcat的

  12-11 11:21:26.664: ERROR/AndroidRuntime(7462): FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
    at android.app.Activity.onCreateView(Activity.java:4242)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
    at android.app.Activity.setContentView(Activity.java:1835)
    at lvs.android.map.MyActivity.onCreate(MyActivity.java:24)
    at android.app.Activity.performCreate(Activity.java:4465)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
    at android.app.ActivityThread.access$600(ActivityThread.java:128)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4514)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:1)

Google Play服务修订版13您必须在manifest.xml中添加一个元标记。将其插入应用程序标记内。因此,您的应用程序标记中将有两个元标记。如果您仍需要任何帮助。只需要请遵循此link

<meta-data  android:name="com.google.android.gms.version" android:value="4030500" />

答案 1 :(得分:0)

基于“java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable”在清单文件中添加:

    <meta-data android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" />

希望这有帮助。

答案 2 :(得分:0)

将此行添加到您的应用标记

 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

您的应用应该如下所示

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MyActivity"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="removed" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>