Java Google maps v2 API集成问题

Java Google maps v2 API集成问题,java,android,google-maps-api-2,Java,Android,Google Maps Api 2,我试图将谷歌地图集成到我的android应用程序中,但在创建apk并在手机上启动(android 4.4.4)后,它崩溃了。若我在emulator上启动,我会收到消息“Failure[安装失败\缺少\共享\库]”。我能做什么 这是我的档案 MainActivity.java private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(saved

我试图将谷歌地图集成到我的android应用程序中,但在创建apk并在手机上启动(android 4.4.4)后,它崩溃了。若我在emulator上启动,我会收到消息“Failure[安装失败\缺少\共享\库]”。我能做什么

这是我的档案

MainActivity.java

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tieride);

    SupportMapFragment mapFragment =
            (SupportMapFragment)     getSupportFragmentManager().findFragmentById(R.id.map);

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        mapFragment.setRetainInstance(true);
    } else {

        mMap = mapFragment.getMap();
    }
    setUpMapIfNeeded();
}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    if (mMap == null) {
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        if (mMap != null) {
            // Enabling MyLocation Layer of Google Map
            mMap.setMyLocationEnabled(true);
        }
    }
}
这是我的布局

<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
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout> 

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="there is my package" >

<application

    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

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

    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="there is my key, which i got from API console"/>


    <uses-library android:name="com.google.android.maps" />

    <permission
            android:name="(there is my app path).permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
    <uses-permission android:name="(there is my app path).permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <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"/>

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

    <activity
        android:screenOrientation="portrait"
        android:name=".login.LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:screenOrientation="portrait"
        android:name=".main.MainActivity"
        android:label="@string/thereismytitle" >
    </activity>
</application>

</manifest>


您的模拟器目标是否设置了谷歌API(谷歌公司)?上次我使用google map api时,我也有同样的体验,在我将目标设置为google api(google Inc.)-api级别(版本)后,它就工作了。

如果你读过同样的帖子,请检查一下:我这么做了。现在emulator像电话一样崩溃,因为您正在使用
SupportMapFragment
确保正确添加了支持库。