这个应用程序无法运行,除非你更新Google Play服务错误。

26

我有些迷茫。 我正在使用Google地图实现Android应用程序。

为了使它工作,我按照一些相当有效的教程进行操作。但是我被这个“:

enter image description here

为了解决这个问题,我在这里这里找到了一些技巧,告诉你要解决此问题,必须针对模拟器采取特殊配置,这是我的配置:

enter image description here

以及安装一些.apk文件到模拟器中。

enter image description here

魔法应该完成,地图应该出现,但我的情况并非如此。

我检查了我的extras是否安装正确:

enter image description here

这是我的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>

这是我的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();
    }
}

以及相应的布局:

<?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>

希望找到一些解决方法或者是我在这里错过了什么,谢谢您提前的帮助。


可能是重复的问题:此应用程序无法运行,除非您通过Bazaar更新Google Play服务 - Jorge Y. C. Rodriguez
事实是,我按照应该修复此错误的步骤进行操作,但对我来说没有任何作用。所以我想知道我可能错过了什么。 - Florent Gz
你的问题有点误导性,因为这个错误是由于在模拟器中尝试运行GPS应用程序引起的,无论如何,这个链接可能会对你有所帮助:https://dev59.com/tXE95IYBdhLWcg3whOLK - Jorge Y. C. Rodriguez
现在我不确定是否正在使用GPS,只是尝试显示一个随机地图。 - Florent Gz
10个回答

19
在Android SDK管理器中,您必须在“Android 4.4.2(API 19)”下安装“Google APIs(x86系统映像)”。退出Eclipse并重新启动。
然后在AVD管理器中创建一个新的Android虚拟设备,并选择“Google APIs x86(Google Inc.)- API Level 19”作为目标。勾选“使用主机GPU”以确保地图的绘制加速。
就这样,这台新的仿真器将预装Play服务,并且它将更快运行,因为它是x86映像。

有没有想过如何使用ADK安装Play并获取模拟器?这应该是可能的,但我找不到它... - Ray Kiddy

15

使用Android Studio,唯一帮助我的方法是将Gradle文件中的Google Play服务版本从最新版本降低到以下版本:

compile 'com.google.android.gms:play-services:4.2.+'

当然,这只是一种临时的“绕过”方式,让您继续运行。


1
在我尝试的所有事情中(运行不同设备和不同操作系统映像),这是最终奏效的!谢谢。 - Fidel
1
它可以在棒棒糖(Android 5.1.1)上运行,但无法在果冻豆(Android 4.2)上运行。请有人解释一下代码背后的逻辑,如果我想在JellyBeans甚至更早版本的Android Apis上运行应用程序会怎么样。谢谢。 - Husnain Iqbal

9

我遇到了一个问题,当我点击“更新”按钮时,它无法正常工作,而是一直卡在循环中。以下方法可以解决这个问题(在Android Studio中):

  • 转到工具 > Android > SDK 管理器
  • 勾选“显示软件包详细信息”选项
  • 在您想要的 Android 版本下(例如我现在使用的是 7.1.1),勾选Google Play Intel x86 Atom 系统镜像 google play intel atom system image
  • 点击应用/确定并让镜像安装完成
  • 现在转到工具 > Android > AVD 管理器
  • 创建虚拟设备
  • 选择其中一个带有 Google Play 徽标的设备:devices with a Google Play logo
  • 在新模拟器中运行您的应用程序。 当您遇到错误时,您现在可以点击“更新”,通过您设备上的 Play 商店更新 Google Play 服务,并在新模拟器中测试您的应用程序。

3
为了避免配置不支持 Google Play 的模拟器的麻烦,请始终使用带有 Play 图标的模拟器enter image description here,如图所示:在 Play 商店行下面显示的 Play 图标

enter image description here

安装兼容谷歌应用商店的模拟器后,再次在模拟器中运行您的应用程序。当您收到“应用程序无法运行除非......”的通知时,请单击该通知并按照屏幕提示进行操作:“使用Gmail帐户登录...输入电子邮件和密码等”,一旦您同意谷歌许可协议,您将获得谷歌应用商店更新屏幕:enter image description here
更新您的谷歌应用商店并再次启动您的应用程序。还请确保您的应用级gradle和gradle具有谷歌依赖项。
应用级gradle build.gradle(Module:app)
dependencies {

}

    apply plugin: 'com.google.gms.google-services'

项目级别的Gradle

"build.gradle(Project:AppName)"

依赖项 {

    classpath 'com.google.gms:google-services:3.2.1'
}

3
虽然提供的答案可以在模拟器上运行,但在真实设备上可能会出现问题,并且这些解决方案在真实设备上无法使用。这可能会发生在安装有过时版本 Google Play 服务的旧设备上。
为了解决这个问题,Google Play 服务库提供一组 API 来检查 Google Play 服务是否可用,主要是 GoogleApiAvailability 类提供了一些方法来处理可用性问题,例如过时版本。
现在,为了检测设备是否可用 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;
}

这个帮助方法通过检查从isGooglePlayServicesAvailable返回的错误代码来判断Google Play服务是否可用。然后调用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
    }
}

希望能对一些人有所帮助。

1

只有当我使用Android Studio中的模拟器时,才会出现这个问题。我通过将google-services插件添加到gradle:app中来解决了这个问题。

apply plugin: 'com.google.gms.google-services'

然后在依赖项中添加

compile 'com.google.android.gms:play-services:9.0.0'

先前我在使用 <\p>。
compile 'com.google.android.gms:play-services:9.4.0'

但是它会报错,提示版本不匹配,并建议使用com.android.gms 9.0.0版本。


1
如果你想使用这个版本 'com.google.android.gms:play-services:9.4.0' 进行编译,那么你应该使用 API 级别为 24 的模拟器。 - Omer

1

我也遇到了同样的错误。通过更新Android Studio及其相关的Android SDK工具进行修复。


1
在Android Studio 3中,进入工具 -> SDK管理器并安装Google Play服务enter image description here

0

我在尝试在Android 7.0上构建时遇到了同样的错误。我在6.0下重新构建,没有任何问题。回退1个API级别也可能对您有所帮助。


0
我通过以下方法解决了这个问题:
1- 确保在SDK工具中安装了“Google Play服务”,就像这张图片一样:

enter image description here

2- 确保 AndroidManifest.xml 文件包含以下行:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

3- 在 build.gradledependencies中添加以下代码:

classpath 'com.google.android.gms:play-services-maps:17.0.0'

注意:您可能需要将play-services-maps的版本从17更改为最新版本,但在2019年8月,17是最新版本...
如此图像:

enter image description here

不要忘记重新构建项目(如果您使用Flutter,请在终端中执行此命令flutter clean

然后您将看到地图正在模拟器上工作:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接