我见过这个:Android Emulator: This app won't run without Google Play services
看起来很相似,但它没有解决我的问题。我已经导入了 google play services 项目,并将其添加到库中,但它仍然给了我这个错误。
该链接的解决方案是更改为模拟器的 Google API,但是 avd 启动时间太长,当我尝试运行我的应用程序时,它花费了非常非常长的时间..
我想显示 Google map ,所以我关注了这个 Youtube 视频: https://www.youtube.com/watch?v=awX5T-EwLPc
我已经完成了以下操作以尝试使其正常工作:
1) 导入 google-play-services_lib 项目
2) 在 SDK 管理器中安装 Google Play 服务
3) 使用正确的 SHA1 创建 API_KEY
4) 模拟器目标:Android 4.4.2 - API 级别 19
5) 当我使用 cmd 运行应用程序时,安装了 com.android.vending-5.0.37-80300037-minAPI9.apk。
6) 使用上述方法在我的模拟器中安装了 Google Play 商店应用。
7) 在 Project --> Properties --> Android --> Library --> 添加了对 google-play-service_lib 项目的引用(添加了 google-play-services_lib 项目)
8)项目构建目标:标准Android平台4.4.2
9) 在 Google 开发者控制台中,我启用了 Google Maps Android API v2
MainActivity.java
package com.rachel.googlemaprouting;
public class MainActivity extends Activity {
private final LatLng LOCATION_SG = new LatLng(1.3499391,103.7492432);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onClick_Singapore(View v){
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_SG, 9);
map.animateCamera(update);
}
}
activity_main.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.rachel.googlemaprouting.MainActivity" >
<!-- <Button
android:id="@+id/btnSingapore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="onClick_Singapore"
android:text="Singapore" />-->
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rachel.googlemaprouting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
<permission
android:name="com.rachel.googlemaprouting.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.rachel.googlemaprouting.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"/>
<!-- 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"/>
<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.maps.v2.API_KEY"
android:value="[MY_API_KEY]"/> // i did fill this up with the api key i gotten.
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<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>
</application>
</manifest>
谁能帮我看看这里有什么问题吗? :/
- LogCat 中没有错误。
当应用程序出现时,它会显示以下内容: “如果没有 Google Play 服务,MapRouting 就无法运行,而您的手机上缺少这些服务。” [获取 Google Play 服务] - 按钮。
运行应用程序时的控制台。
[2015-06-01 18:54:48 - MapRouting] ------------------------------ [2015-06-01 18:54:48 - MapRouting] Android Launch! [2015-06-01 18:54:48 - MapRouting] adb is running normally. [2015-06-01 18:54:48 - MapRouting] Performing com.rachel.googlemaprouting.MainActivity activity launch [2015-06-01 18:54:48 - MapRouting] Automatic Target Mode: using existing emulator 'emulator-5556' running compatible AVD 'myAVD' [2015-06-01 18:54:48 - MapRouting] Uploading MapRouting.apk onto device 'emulator-5556' [2015-06-01 18:54:51 - MapRouting] Installing MapRouting.apk... [2015-06-01 18:55:14 - MapRouting] Success! [2015-06-01 18:55:14 - MapRouting] Starting activity com.rachel.googlemaprouting.MainActivity on device emulator-5556 [2015-06-01 18:55:17 - MapRouting] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.rachel.googlemaprouting/.MainActivity }
This app won't run without Google Play Services, which are missing from your phone
在此链接中,他们说我们无法在模拟器上查看 map ,但在 Youtube 视频中,youtube 可以..
请帮忙...
最佳答案
您可能已经注意到,应用中的 Google map 需要手机安装 Google Play 服务。我认为就您而言,您的模拟器没有 Google Play 服务。
您过去必须手动将其单独安装到模拟器上,但 Google 有 officially supported 4.4.2之后。
您现在需要做的就是下载模拟器目标:
并将其设置为Google API (Google Inc.) - API Level 19
,而不是Android 4.4.2 - API 级别 19
。
请注意,模拟器速度很慢,第一次运行应用程序时,可能需要几分钟才能开始渲染 map 。 (您会看到带有 map Controller 的灰屏)
即使模拟器可以工作,在真实设备上测试您的应用程序始终是最好的选择,特别是当您使用 Google Play 服务时。
希望这有帮助。
关于java - Eclipse Java Android - 如果没有 Google Play 服务,该应用程序将无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30574595/