问题描述
在 Android 应用中集成 Google Plus 登录按钮时,我发现按钮在实际设备和模拟器中的显示方式存在一些差异.我知道 Google Plus 服务 APK 未安装在模拟器中,但这可以通过从设备中提取 APK 并使用 APK 将它们安装到模拟器中来解决.
When integrating a Google Plus login button in an Android app, I'm observing some differences in how the button appears on an actual device and in the emulator. I am aware of the fact that the Google Plus services APKs are not installed in the emulator, but this can be worked around by pulling the APKs from a device and installing them into the emulator using APK.
我当前的实现"只是在布局中包含登录按钮,通过使用以下 XML 代码引用按钮:
My current "implementation" simply includes the login button in a layout, by referring to the button with the following XML code:
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
当我在设备上测试我的应用程序时,根据此处提到的指南 https://developers.google.com/+/mobile/android/sign-in .但是在模拟器上运行时,它只是一个普通按钮(灰色背景,黑色文本),上面写着使用 Google 登录".
When I test my app on the device, the button appears all red and shiny, according to the guidelines mentioned here https://developers.google.com/+/mobile/android/sign-in . But when running on the emulator, it's just a normal button (grey background with black text) saying "Sign in with Google".
知道为什么结果不同吗?我已经确定我正在运行相同的 API 级别,并且资源似乎也被正确地拉入了模拟器,因为它显示了实际的登录按钮(但外观不同).
Any idea why the results are different? I've made sure I'm running the same API level, and the resource does seem to get pulled in correctly also on the emulator since it shows the actual login button (but with a different look).
更新:在logcat中找到了线索;消息未找到登录按钮,请改用占位符."几乎可以解释为什么我在模拟器上看到灰色沉闷的按钮.仍然需要弄清楚原因;可能是从设备复制 google plus apk"黑客无法正常工作.
Update: Found a clue in logcat; the message "Sign in button not found, using placeholder instead." pretty much explains why I'm seeing the grey dull button on the emulator. Still need to figure out why; could be the "copy google plus apk's from device" hack isn't working properly.
推荐答案
Google Play 服务在 4.2.2 版本的 Android Emulator 上运行,并得到官方支持,如 Android 文档:设置 Google Play 服务.
Google Play services works on the 4.2.2 versions of the Android Emulator and is officially supported as described in the Android documentation: Setup Google Play Services.
更新
您现在可以将 Intel/x86 映像(HAXM 兼容)用于 API 19 和更新版本,对于 ARM,Google Play 服务可用于大多数映像.
You now can use the Intel/x86 images (HAXM-compatible) for API 19 and newer and for ARM, Google Play Services is available on most images.
设置图片
要为您的虚拟设备管理器获取正确的映像:
To get the right image for your virtual device manager:
- 打开 Android SDK 管理器
- 打开群组 Android 4.2.2 (API 17)
- 检查 Google API
- 检查 ARM EABI v7a 系统映像
创建虚拟设备:
- 打开 Android 虚拟设备管理器
- 创建一个新设备
- 输入 AVD 名称
- 将目标设置为 Google APIs (Google Inc.) - API Level 17
- 保存您的虚拟设备并启动它...
注意 CPU/ABI 将被固定为 ARM
现在您应该可以在模拟器中使用 Google Play 服务了.值得注意的是,您需要在 Android 项目中将目标适当地设置为 Google API,以便 Google Play 服务正常工作.
Now you should be able to use the Google Play Services in the emulator. Of note, you need to set your target appropriately in your Android project to the Google APIs in order for Google Play Services to work.
这篇关于模拟器中的 Google Play 服务,实现 Google Plus 登录按钮等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!