Google Map API v2无法正常工作:Emulator&设备

时间:2015-04-17 01:45:23

标签: android google-maps

您好我按照教程:http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/

随后尝试按照stackfoverflow类似帖子的建议,即将MapFragment更改为SupportMapFragment等。但是我的应用程序仍然崩溃了以下错误:

Logcat:

04-16 21:23:56.328: D/dalvikvm(2312): Not late-enabling CheckJNI (already on)
04-16 21:23:56.498: I/dalvikvm(2312): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzg
04-16 21:23:56.498: W/dalvikvm(2312): VFY: unable to resolve virtual method 508: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
04-16 21:23:56.498: D/dalvikvm(2312): VFY: replacing opcode 0x6e at 0x000b
04-16 21:23:56.498: D/AndroidRuntime(2312): Shutting down VM
04-16 21:23:56.498: W/dalvikvm(2312): threadid=1: thread exiting with uncaught exception (group=0xb2cc1b20)
04-16 21:23:56.508: E/AndroidRuntime(2312): FATAL EXCEPTION: main
04-16 21:23:56.508: E/AndroidRuntime(2312): Process: com.diwesh.googlemaptest, PID: 2312
04-16 21:23:56.508: E/AndroidRuntime(2312): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.diwesh.googlemaptest/com.diwesh.googlemaptest.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.os.Looper.loop(Looper.java:136)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at java.lang.reflect.Method.invokeNative(Native Method)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at java.lang.reflect.Method.invoke(Method.java:515)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at dalvik.system.NativeStart.main(Native Method)
04-16 21:23:56.508: E/AndroidRuntime(2312): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.Activity.setContentView(Activity.java:1929)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.diwesh.googlemaptest.MainActivity.onCreate(MainActivity.java:18)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.Activity.performCreate(Activity.java:5231)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-16 21:23:56.508: E/AndroidRuntime(2312):     ... 11 more
04-16 21:23:56.508: E/AndroidRuntime(2312): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 7095000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.common.GooglePlayServicesUtil.zzJ(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.maps.internal.zzx.zzad(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.maps.internal.zzx.zzac(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.maps.SupportMapFragment$zzb.zzqs(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.dynamic.zza.zza(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
04-16 21:23:56.508: E/AndroidRuntime(2312):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
04-16 21:23:56.508: E/AndroidRuntime(2312):     ... 21 more

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.diwesh.googlemaptest"
    android:versionCode="1"
    android:versionName="1.0" >

      <uses-permission android:name="com.diwesh.googlemaptest.googlemapsv2.permission.MAPS_RECEIVE" />

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

    <permission
        android:name="com.diwesh.googlemaptest.googlemapsv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />





    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />





    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



          <!-- Google Maps API Key -->
<!--    <meta-data
     android:name="com.google.android.maps.v2.API_KEY"
     android:value="Mykey" />
 -->

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


    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

您尚未定义meta-data

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

使用Google Play Services API

时需要

AndroidManifest.xml中添加此部分,并确保已将google play api libs链接到您的应用项目