简体   繁体   English

如何在 Android 模拟器中下载 Google Play 服务?

[英]How to download Google Play Services in an Android emulator?

I want to use Google Play Services API in my application, but when I open the emulator to test my application it sends me a message that says "Google Play Services must be downloaded".我想在我的应用程序中使用 Google Play 服务 API,但是当我打开模拟器来测试我的应用程序时,它会向我发送一条消息,上面写着“必须下载 Google Play 服务”。 I know that occurs because I coded this test in my MainActivity in the method onResume() .我知道会发生这种情况,因为我在MainActivityonResume()方法中编写了这个测试。
I want to know how I can install Google Play Services in my emulator, because soon I will need to test my maps.我想知道如何在我的模拟器中安装 Google Play 服务,因为很快我将需要测试我的地图。

Check out Setting Up Google Play Services which says:查看设置 Google Play 服务,其中说:

To develop an app using the Google Play services APIs , you need to set up your project with the Google Play services SDK.要使用Google Play 服务 API开发应用程序,您需要使用 Google Play 服务 SDK 设置您的项目。

If you haven't installed the Google Play services SDK yet, go get it now by following the guide to Adding SDK Packages .如果您尚未安装 Google Play 服务 SDK,请按照添加 SDK 包的指南立即获取它。

To test your app when using the Google Play services SDK, you must use either:要在使用 Google Play 服务 SDK 时测试您的应用,您必须使用:

  • A compatible Android device that runs Android 2.3 or higher and includes Google Play Store.运行 Android 2.3 或更高版本并包含 Google Play 商店的兼容 Android 设备。
  • The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher.带有AVD的 Android 模拟器,它运行基于 Android 4.2.2 或更高版本的 Google API 平台。

For api 21+ you can use system image with Google Play as I describe below.对于api 21+ ,您可以将系统映像与 Google Play 一起使用,如下所述。

For api 19+ (Android 4.4 Kitkat) you can use system image x86 with Google Api (I was able to use it).对于api 19+ (Android 4.4 Kitkat),您可以将系统映像 x86 与 Google Api 一起使用(我能够使用它)。

For api 17+ (Android 4.2.2) you can TRY to use system image ARM with Google Api (It didn't work for me).对于api 17+ (Android 4.2.2),您可以尝试将系统映像 ARM 与 Google Api 一起使用(它对我不起作用)。

I was able to install Google Play and Google Services as separate apks to pure system image api 16 and 17, but they don't really work after that (services crush and play not opens).我能够将 Google Play 和 Google Services 作为单独的 apk 安装到纯系统映像 api 16 和 17,但在那之后它们并没有真正工作(服务粉碎和播放不打开)。 So seems like it is not possible to make them work on pure AVD image because they should be installed with root access.所以似乎不可能让它们在纯 AVD 映像上工作,因为它们应该以 root 访问权限安装。 The same for updating Google Services on AVD system image with Google API preinstalled - can't update because of incompatible certificates, can't uninstall even using adb because don't have access.在预装了 Google API 的 AVD 系统映像上更新 Google 服务也是如此 - 由于证书不兼容而无法更新,即使使用 adb 也无法卸载,因为无权访问。


How to setup AVD system image with Google Play如何使用 Google Play 设置 AVD 系统映像

Now even better solution exist: using AVD image with build-in Google Play Services.现在有更好的解决方案:使用带有内置 Google Play 服务的 AVD 图像。 It will enable you to use Google Services including Google Play.它将使您能够使用包括 Google Play 在内的 Google 服务。 Also you will be able update it without re-creating AVD image.您也可以在不重新创建 AVD 映像的情况下对其进行更新。

Open AVD manager and choose create new device.打开 AVD 管理器并选择创建新设备。 You should use device definition with play store icon.您应该使用带有 Play 商店图标的设备定义。

1

Then choose system image for it.然后为其选择系统映像。 You should choose one with Google Play and NOT with Google API.您应该使用Google Play不是使用 Google API 选择一种。

2

Then launch new device.然后启动新设备。

3

You can update Play Services as shown on screenshot, or manually on device..您可以如屏幕截图所示更新播放服务,也可以在设备上手动更新。

4

This is how you make Android Google Maps API v2 work on your emulator.这就是您如何让 Android Google Maps API v2 在您的模拟器上运行。


Create a new emulator创建一个新的模拟器

  • for device choose "5.1'' WVGA (480 x 800: mdpi)"对于设备选择“5.1'' WVGA (480 x 800: mdpi)”
  • for target choose "Android 4.1.2 - API level 16"对于目标选择“Android 4.1.2 - API level 16”
  • for "CPU/ABI" choose "ARM"对于“CPU/ABI”选择“ARM”
  • leave rest to defaults保留默认设置

these are the settings that are working for me.这些是对我有用的设置。 I don't know for different ones.我不知道不同的。


Start the emulator启动模拟器


install com.android.vending-1.apk and com.google.android.gms-1.apk via ADB install command通过 ADB install 命令安装com.android.vending-1.apkcom.google.android.gms-1.apk


The longer answer is on my blog post about this issue https://medium.com/nemanja-kovacevic/how-to-make-android-google-maps-v2-work-in-android-emulator-e384f5423723更长的答案在我关于这个问题的博客文章中https://medium.com/nemanja-kovacevic/how-to-make-android-google-maps-v2-work-in-android-emulator-e384f5423723

I came across another solution to use the Google play services on an emulator.我遇到了另一种在模拟器上使用 Google Play 服务的解决方案。 The guys at http://www.genymotion.com/ provide very fast emulators on which you can install Google play services. http://www.genymotion.com/上的人提供了非常快速的模拟器,您可以在上面安装 Google Play 服务。 They just need you to sign up to begin downloading and you need Virtual box installed.他们只需要您注册即可开始下载,并且您需要安装 Virtual box。 At the moment they cater for Android 16 and 17 but more are on the way.目前他们迎合 Android 16 和 17,但更多的正在开发中。

在当前版本 (Android Studio 0.5.2) 中,现在有一个设备类型为“Google APIs x86 (Google Inc.) - API Level 19”。

The key is to select the target of your emulator to, for example: Google APIs (ver 18) .关键是选择你的模拟器的目标,例如: Google APIs (ver 18) If you select, for example, just Jellybean 18 (without API) you will not be able to test apps that require Google services such as map.例如,如果您选择Jellybean 18 (无 API),您将无法测试需要 Google 服务(例如地图)的应用程序。 Keep in mind that you must first download the Google API of your favorite version with the Android SDK Manager.请记住,您必须首先使用 Android SDK 管理器下载您喜欢的版本的 Google API。

This is a good practice and it is far better than juggling with most workarounds.这是一个很好的做法,它比使用大多数解决方法要好得多。

I tried to develop google MAP API V2 application recently and tried to run it through emulator but I everytime it showed me error "Google Play Servcies is not installed in this phone".我最近尝试开发 google MAP API V2 应用程序并尝试通过模拟器运行它,但每次它都显示错误“此手机中未安装 Google Play Servcies”。 From my perpective even I think google MAP API V2 doesn't work on emulator.从我的角度来看,即使我认为 google MAP API V2 在模拟器上也不起作用。

Solution解决方案

Then I tried to run the same example on my Sony Experia you and again it showed me same error.然后我尝试在我的 Sony Experia 上运行相同的示例,它再次向我显示相同的错误。 Then I installed google play services on my mobile and amazingly it started working..:)))然后我在我的手机上安装了谷歌播放服务,令人惊讶的是它开始工作了..:)))

I got it working by我得到它的工作

  • Installing the Google Play Services through the Android SDK Manager通过 Android SDK 管理器安装 Google Play 服务
  • Using a Galaxy Nexus Device (4.65", 720 x 1280: xhdpi)使用 Galaxy Nexus 设备(4.65 英寸,720 x 1280:xhdpi)
  • Targeting the Android 4.2.2 Google API Level 17针对 Android 4.2.2 Google API 级别 17

Go to https://university.xamarin.com/resources/working-with-android-emulators .转到https://university.xamarin.com/resources/working-with-android-emulators Scroll down to the "Installing Google Play Services" section.向下滚动到“安装 Google Play 服务”部分。 Step by step walk through there.一步一步地走过那里。

Directly plagarized from xamarin here so I don't get dinged for linking and not including solution.在这里直接从 xamarin 剽窃,所以我不会因为链接而不包括解决方案而感到厌烦。 Posting this as I found the hit in stack before I found the solution that worked across the board on the xamarin page.在我在 xamarin 页面上找到全面工作的解决方案之前,我在堆栈中找到了命中。

  1. Start the Xamarin Android Player and run one of the supplied images, the following assumes you have started the KitKat Nexus 4 image.启动 Xamarin Android Player 并运行提供的图像之一,以下假设您已启动 KitKat Nexus 4 图像。 Download the proper Google Play Services .zip file from www.teamandroid.com/gapps/ .从 www.teamandroid.com/gapps/ 下载适当的 Google Play 服务 .zip 文件。 Make sure to download the image appropriate for your version of Android.确保下载适合您的 Android 版本的图像。
  2. Drag the .zip file onto the running emulator and drop it to install the component, here we show it on Mac OS X, but the same mechanism is used in Windows.将 .zip 文件拖到正在运行的模拟器上并放下它以安装组件,这里我们在 Mac OS X 上显示它,但在 Windows 中使用相同的机制。 You will get a prompt to install the package onto the emulator which indicates the image will be restarted您将收到将软件包安装到模拟器上的提示,这表明映像将重新启动
  3. Once it restarts, you will get a notification that installation is completed, and the image will now have Google Maps, Google+ and support for the Google Play store.重新启动后,您将收到安装完成的通知,并且该图像现在将具有 Google 地图、Google+ 和对 Google Play 商店的支持。 Note that some things do not work correctly and you may get a few errors from some of the services, but you can safely dismiss these and continue the instructions.请注意,有些事情无法正常工作,并且您可能会从某些服务中得到一些错误,但您可以放心地忽略这些并继续说明。
  4. Next, you will need to associate a Google account so that you can update the services using the Google Play store.接下来,您需要关联一个 Google 帐户,以便您可以使用 Google Play 商店更新服务。 It should prompt you for this, but if it does not, you can go into the Google Settings and add a new account.它应该会提示您这样做,但如果没有,您可以进入 Google 设置并添加一个新帐户。 Once you've added the account, you can then update the Google apps by opening the Google Play store application and going into settings from the side bar menu.添加帐户后,您可以通过打开 Google Play 商店应用程序并从侧栏菜单进入设置来更新 Google 应用程序。
  5. Select Settings and then scroll down to the Build Version number information and double-tap on it until it tells you it is either up-to-date, or that it will download and install a new version.选择设置,然后向下滚动到构建版本号信息并双击它,直到它告诉您它是最新的,或者它将下载并安装新版本。
  6. Power off the device (press and hold the power button in the toolbar on the right) and restart it.关闭设备(按住右侧工具栏中的电源按钮)并重新启动设备。 Once it restarts, it should indicate that it needs to update the Google Play services, tapping the notification will open the Google Play Store and install the latest version重启后应该提示需要更新 Google Play 服务,点击通知会打开 Google Play 商店并安装最新版本

Now you can run applications that depend on Google Maps in the Xamarin Android Player.现在,您可以在 Xamarin Android Player 中运行依赖于 Google 地图的应用程序。

To the latest setup and information if you have installed the Android Studio (ie 1.5) and trying to target SDK 4.0 then you may not be able to locate and setup the and AVD Emulator with SDK-vX.XX (with Google API's).如果您已安装 Android Studio(即 1.5)并尝试以 SDK 4.0 为目标,那么您可能无法找到并设置带有 SDK-vX.XX(带有 Google API)的 AVD Emulator 和 AVD Emulator。

See following steps in order to download the required library and start with that.请参阅以下步骤以下载所需的库并开始。 AVD Emulator setup -setting up Emulator for SDK4.0 with GoogleAPI so Map application can work- In Android Studio AVD 模拟器设置 - 使用 GoogleAPI 为 SDK4.0 设置模拟器,以便地图应用程序可以工作 - 在 Android Studio 中

But unfortunately above method did not work well on my side.但不幸的是,上述方法对我来说效果不佳。 And was not able to created Emulator with API Level 17 (SDK 4.2).并且无法使用 API 级别 17 (SDK 4.2) 创建模拟器。 So I followed this post that worked on my side well.所以我关注了这篇对我来说效果很好的帖子。 The reason seems that the Android Studio Emulator creation window has limited options/features.原因似乎是 Android Studio Emulator 创建窗口的选项/功能有限。

Google Play Services in emulator, implementing Google Plus login button etc 模拟器中的 Google Play 服务,实现 Google Plus 登录按钮等

I know this is an old question, but I got here because I had a similar problem as everyone above.我知道这是一个老问题,但我来到这里是因为我遇到了与上述每个人类似的问题。 I solved it by just reading a little closer!我通过仔细阅读来解决它!

I hadn't noticed there were 2 possible system Images I could choose from, one that contained Google APIs and one that didn't (on my laptop the menu was too small for me to read the (with Google APIs) text appended.我没有注意到我可以选择 2 个可能的系统映像,一个包含 Google API,另一个不包含(在我的笔记本电脑上,菜单太小,我无法阅读附加的(使用 Google API)文本。

It's a stupid thing to miss, but someone else might have a small screen like I did, and miss this :D错过这是一件愚蠢的事情,但其他人可能像我一样有一个小屏幕,错过了这个:D

If your emulator x86 this method works your me.如果你的模拟器 x86 这个方法对你有用。

Download and install http://opengapps.org/app/opengapps-app-v16.apk .下载并安装http://opengapps.org/app/opengapps-app-v16.apk And select nano pack并选择纳米包

More info http://opengapps.org/app/更多信息http://opengapps.org/app/

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM