无法在设备'emulator-5554'上安装Map.apk

时间:2013-12-05 21:24:56

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

我是Android界的新手,我需要使用Google Maps Android API创建应用。我按照以下说明操作:

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

每当我启动AVD时,我都会收到错误:

[2013-12-05 21:04:37 - Map] Failed to install Map.apk on device 'emulator-5554!
[2013-12-05 21:04:37 - Map] (null)
[2013-12-05 21:04:38 - Map] Launch canceled!

我的主要活动代码:

package com.example.map;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

我的MainActivity XML文件:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/>

和我的Manifest.xml文件:

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

    <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"/>
    <!-- The following two permissions are not required to use
         Google Maps Android API v2, but are recommended. -->
    <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"/>

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

    <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.xxxxxxxxxHIDDENxxxxxxxx"
    android:value="xxxxxxxxxHIDDENxxxxxxxx"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.map.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>
    </application>

</manifest>

还尝试了这里提供的代码:

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

是MainActivity文件代码:

package com.example.map;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

        // Get a handle to the Map Fragment
        GoogleMap map = ((MapFragment) getFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        LatLng sydney = new LatLng(-33.867, 151.206);

        map.setMyLocationEnabled(true);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));

        map.addMarker(new MarkerOptions()
                .title("Sydney")
                .snippet("The most populous city in Australia.")
                .position(sydney));
    }
}

任何想法?

2 个答案:

答案 0 :(得分:1)

我建议的第一件事是不向公众展示您的API密钥;对于开发应用程序的人来说,这应该是私有的。

此元标记的格式也是错误的:

   <meta-data
    android:name="com.google.android.maps.v2.AIzaSyB7AMKbYsVajgb6D0zpq9wUODX9gdR2DhE"
    android:value="AIzaSyB7AMKbYsVajgb6D0zpq9wUODX9gdR2DhE"/>

您正在复制名称末尾的API密钥。我强烈建议您创建一个新的API密钥,不要使用您向公众公开的密钥。可能还有其他错误,但没有堆栈跟踪很难说。

答案 1 :(得分:0)

请参阅此页:http://developer.android.com/google/play-services/setup.html

具体来说:

  

要在使用Google Play服务SDK时测试您的应用,您必须使用   之一:

     
      
  • 运行Android 2.3或更高版本且包含Google Play商店的兼容Android设备。
  •   
  • 带有AVD的Android模拟器,可运行基于Android 4.2.2或更高版本的Google API平台。
  •   

因此,请确保您使用的模拟器是Android 4.2.2或更高版本。如果低于此级别,则模拟器上不提供Google Play服务,您必须使用物理Android设备对其进行测试。

如果您必须在较低端的设备模拟器上进行测试,可以采用相应的解决方法,但Google不会对它们进行正式支持,因此您的里程可能会有所不同。

查看此链接: Custom emulator that supports Google Maps API

相关问题