Android 除非您更新 Google Play 服务错误,否则此应用不会运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23450007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
This app won't run unless you update Google Play services error
提问by Florent Gz
I'm kind of lost right now. I'm implementing an Android application using Google maps.
我现在有点迷失了。我正在使用 Google 地图实现一个 Android 应用程序。
In order to make it work I followed some tutorials which were pretty efficient. However I'm stuck with this ":
为了使它工作,我遵循了一些非常有效的教程。但是我坚持这个“:
To fix, this problem I found some tricks hereor herewhich tell that to solve this issue you have to take a special configuration for the emulator, here is mine:
为了解决这个问题,我在这里或这里找到了一些技巧,告诉你要解决这个问题,你必须对模拟器进行特殊配置,这是我的:
and to install some .apk on the emulator.
并在模拟器上安装一些.apk。
And the magic is supposed to be done and the map is supposed to appear which is not my case.
魔法应该完成,地图应该出现,这不是我的情况。
I checked that my extras were well installed:
我检查了我的附加组件是否安装良好:
Here is my AndroidManifest:
这是我的 AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypack"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="16"/>
<permission android:name="mypack.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="mypack.permission.MAPS_receive"/>
<!-- Permission pour utiliser la connexion internet -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Permission permettant de vérifier l'état de la connexion -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission pour stocker des données en cache de la map -->
<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" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<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" />
<activity android:name="Home"
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>
Here is my MainActivity
这是我的主要活动
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class Home extends Activity {
/**
* Called when the activity is first created.
*/
private GoogleMap map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
and the corresponding layout:
和相应的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Hope to find some fix or what I missed here, thank you in advance.
希望能找到一些修复或我在这里错过的东西,提前谢谢你。
采纳答案by BladeCoder
In the Android SDK Manager, you must install "Google APIs (x86 System Image)" under "Android 4.4.2 (API 19)". Quit Eclipse and restart it.
在 Android SDK Manager 中,您必须在“Android 4.4.2 (API 19)”下安装“Google APIs (x86 System Image)”。退出 Eclipse 并重新启动它。
Then create a new android virtual device in AVD manager and choose "Google APIs x86 (Google Inc.) - API Level 19" as target. Check "Use Host GPU" to ensure the drawing of the map will be accelerated.
然后在 AVD 管理器中创建一个新的 android 虚拟设备并选择“Google APIs x86 (Google Inc.) - API Level 19”作为目标。勾选“使用主机 GPU”以确保地图绘制将被加速。
That's it, this new emulator will have Play Services preinstalled and it will run faster because it's a x86 image.
就是这样,这个新的模拟器将预装 Play 服务,运行速度会更快,因为它是 x86 映像。
回答by dvrm
using android studio, the only thing that helped me was to reduce the google play services version in the gradle file from the last version to this:
使用 android studio,唯一帮助我的是将 gradle 文件中的 google play 服务版本从上一个版本减少到这个:
compile 'com.google.android.gms:play-services:4.2.+'
(ofcourse,this is a temporary "bypass" to enable you continue running)
(当然,这是一个临时的“绕过”,使您能够继续运行)
回答by james246
I had a problem getting this error and hitting the 'Update' button did nothing, it was stuck on a loop, what worked is the following (in Android Studio):
我在收到此错误时遇到问题,点击“更新”按钮什么也没做,它卡在一个循环中,以下是有效的(在 Android Studio 中):
- Go to Tools > Android > SDK Manager
- Check the 'Show Package Details' option
- Under the Android version you want (7.1.1 for me right now), check Google Play Intel x86 Atom System Image
- Hit Apply/OK and let the image install
- Now go to Tools > Android > AVD Manager
- Create Virtual Device
- Select one of the devices with a Google Play logo:
- Run your app in the new emulator. You can now hit 'Update' when you get the error, update Google Play Services via the Play Store on your device, and test your app in peace.
回答by RileyManda
To save yourself the trouble of configuring an emulator that does not have google play support,always use an emulator with the playicon
为了省去配置没有 google play 支持的模拟器的麻烦,请始终使用带有playicon的模拟器
as depicted in the image:The play iconpresent under the Playstore row.
如图所示:Playstore 行下方的播放图标。
After installing the google play compatible emulator...run your app in the emulator again...and when you get the notification"App wont run unless......"click on the notification and follow the screen prompts:"Signing In using a gmail account...email and password etc",as soon as you agree to the google licence youl get the google play update screen:
安装谷歌播放兼容模拟器后...再次在模拟器中运行您的应用程序...当您收到通知“应用程序不会运行,除非......”点击通知并按照屏幕提示进行操作:“签名在使用 Gmail 帐户...电子邮件和密码等”时,只要您同意 google 许可,您就会获得 google play 更新屏幕:
update your google play and launch your app again. Also make sure you have the google dependencies in your app level gradle and gradle:
更新您的 google play 并再次启动您的应用。还要确保您的应用程序级别 gradle 和 gradle 中具有 google 依赖项:
App level gradle build.gradle(Module:app)
应用级 gradle build.gradle(Module:app)
dependencies {
}
apply plugin: 'com.google.gms.google-services'
Project level Gradle "build,gradle(Project:AppName)"
项目级 Gradle “build,gradle(Project:AppName)”
dependencies {
依赖{
classpath 'com.google.gms:google-services:3.2.1'
}
回答by Leo
While the provided answers will work for an emulator, this could be a real issue on a real device and these solutions will not work on a real device. This could happen on an old device that has an outdated version of Google Play Services.
虽然提供的答案适用于模拟器,但这在真实设备上可能是一个真正的问题,这些解决方案在真实设备上不起作用。这可能发生在具有过时版本的 Google Play 服务的旧设备上。
To overcome this issue, the Google Play Services library has a set of APIs to check the availability of Google Play Services, mainly the GoogleApiAvailability
class provides a few methods to handle availability issues such as an outdated version.
为了克服这个问题,Google Play Services 库有一组 API 来检查 Google Play Services 的可用性,主要是GoogleApiAvailability
该类提供了一些方法来处理可用性问题,例如版本过时。
Now, to detect whether a device has Google Play Services available or not, what I normally do is create a helper method to run the check
现在,要检测设备是否有可用的 Google Play 服务,我通常做的是创建一个辅助方法来运行检查
private boolean checkPlayServices(){
GoogleApiAvailability gaa = GoogleApiAvailability.getInstance();
int result = gaa.isGooglePlayServicesAvailable(getApplicationContext());
if(result != ConnectionResult.SUCCESS){
if(gaa.isUserResolvableError(result)){
gaa.getErrorDialog(this,result, REQUEST_PLAY_SERVICES_RESOLUTION).show();
}
return false;
}
return true;
}
This helper method checks whether Google Play Services is available or not by inspecting the error code returned from isGooglePlayServicesAvailable
. Then it calls isUserResolvableError
to determine if the error is resolvable by the user (e.g. by updating Google Play Services). If it is resolvable, then a dialog is displayed for the user to confirm he wants the system to resolve the error. Then call it on the Activity's onCreate
method, I run that check as below
此辅助方法通过检查从 返回的错误代码来检查 Google Play 服务是否可用isGooglePlayServicesAvailable
。然后它调用isUserResolvableError
以确定错误是否可由用户解决(例如,通过更新 Google Play 服务)。如果它是可解决的,则会显示一个对话框供用户确认他希望系统解决错误。然后在 Activity 的onCreate
方法上调用它,我运行该检查如下
//I normally assume Google Play services is available
private boolean playServicesAvailable = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_selector);
//check for rare case where Google Play Services is not available
playServicesAvailable = checkPlayServices();
if(!playServicesAvailable){
//hide UI elements and turn off features that rely on Google Play Services
}
}
Hope it helps some out there
希望它可以帮助一些那里
回答by onmyway133
回答by josua josh
I got this problem only when I am using android emulator from Android Studio. I solved the problem by adding google-services plugin to gradle:app
仅当我使用 Android Studio 的 android 模拟器时才会遇到此问题。我通过向 gradle:app 添加 google-services 插件解决了这个问题
apply plugin: 'com.google.gms.google-services'
then on the dependencies add
然后在依赖项上添加
compile 'com.google.android.gms:play-services:9.0.0'
previously I was using
以前我使用
compile 'com.google.android.gms:play-services:9.4.0'
but it gives error that there is a version mismatch and it suggest to use com.android.gms version 9.0.0
但它给出了版本不匹配的错误,它建议使用 com.android.gms 版本 9.0.0
回答by george mano
I had the same error. Fixed it by updating Android Studio along with its related Android SDK Tools.
我有同样的错误。通过更新 Android Studio 及其相关的 Android SDK 工具来修复它。
回答by Mr_Dave
I encountered this same error trying to build on Android 7.0. I rebuilt under 6.0 and didn't have any issues. Reverting back 1 API level may help you as well.
我在尝试在 Android 7.0 上构建时遇到了同样的错误。我在 6.0 下重建,没有任何问题。恢复 1 个 API 级别也可能对您有所帮助。
回答by AnasSafi
I Solved this problem by:
我通过以下方式解决了这个问题:
1- Make sure "Google Play Services" is installed in SDK tools, Like this image:
1- 确保在SDK 工具中安装了“Google Play 服务” ,如下图所示:
2- Make sure AndroidManifest.xmlfile contain this lines:
2- 确保AndroidManifest.xml文件包含以下几行:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
3- In dependenciesof build.gradleadd this line:
3-在依赖关系的的build.gradle添加此行:
classpath 'com.google.android.gms:play-services-maps:17.0.0'
Note: you may need change version of play-services-maps from 17 to latest, but 17 is latest in Aug 2019 ...
注意:您可能需要将 play-services-maps 的版本从 17 更改为最新版本,但 17 是 2019 年 8 月的最新版本......
As this image:
如这张图片:
Don not forget to rebuild the project (if you use flutter do this command in terminal flutter clean)
不要忘记重建项目(如果您使用 flutter 在终端flutter clean 中执行此命令)
Then you will see the map is working on emulator:
然后你会看到地图正在模拟器上工作: