配对 Android 和 Wear 模拟器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25205888/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:12:49  来源:igfitidea点击:

Pairing Android and Wear emulators

androidemulationwear-os

提问by user2498079

I don't have an Android Wear, nor do I have a phone running 4.3. Is there a way to connect the JB 4.3 emulator and Android Wear emulator for app development?

我没有 Android Wear,也没有运行 4.3 的手机。有没有办法将 JB 4.3 模拟器和 Android Wear 模拟器连接起来进行应用程序开发?

采纳答案by Wayne Piekarski

Using an emulated Android 4.3 device connected to a Wear emulator is not supported at this time.

目前不支持使用连接到 Wear 模拟器的模拟 Android 4.3 设备。

回答by reVerse

After reading a blog posta few days ago I finally managed to connect an emulated Android-Device to a Wear-Emulator.
Here are the different steps that are necessary:

几天前阅读了一篇博客文章后,我终于设法将模拟的 Android-Device连接到 Wear-Emulator
以下是必要的不同步骤:

Step #1

第1步

Create a new emulator that is based on the Google APIs platform, otherwise you won't be able to run the Android Wear Companion app since it requires the Google Play Services. (See Android Developer site)

创建一个基于Google API 平台的新模拟器,否则您将无法运行 Android Wear Companion 应用,因为它需要Google Play 服务。(请参阅 Android 开发者网站

Emulator with Google APIs

带有 Google API 的模拟器

Step #2

第2步

Start the Phone Emulator and install the Android Wear Companionapp via the following command

启动Phone Emulator并通过以下命令安装Android Wear Companion应用

adb install name_of_the_file.apk

adb install name_of_the_file.apk

You can download the latest apk from here.

你可以从这里下载最新的 apk 。

Step #3

第 3 步

Start the Wear-Emulator.

启动磨损模拟器。

Step #4

第四步

Open the Android Wear App on the Phone Emulator. Accept the TOS and so on.

在手机模拟器上打开 Android Wear 应用。接受 TOS 等。

Step #5

第 5 步

Open your command prompt and make sure both emulators are recognized with the following command

打开命令提示符并确保使用以下命令识别两个模拟器

adb devices

亚行设备

Output should be something like this:

输出应该是这样的:

List of devices attached
emulator-5554   device
emulator-5556   device

In my case emulator-5556is the Phone. You can find this by looking at the Window-Title of the emulator.
See the following Screenshot:

在我的情况下emulator-5556是电话。您可以通过查看模拟器的 Window-Title 找到它。
请参阅以下屏幕截图:

Emulator window title

模拟器窗口标题

Step 6

第 6 步

Open your command prompt once again and start a telnet sessionon the port of your smartphone emulator:

再次打开命令提示符并telnet session在智能手机模拟器的端口上启动:

telnet localhost 5556

远程登录本地主机 5556

Afterwards it'll try to connect and if it succeeds it'll show a new window saying something like this:

之后它将尝试连接,如果成功,它将显示一个新窗口,内容如下:

Android Console: type 'help' for a list of commands
OK

Now enter the following command:

现在输入以下命令:

redir add tcp:5601:5601

redir 添加 tcp:5601:5601

Afterwards it should say OK.

之后它应该说OK

Step 7

第 7 步

Open the Android-Wear companion app once again and click on the watch-iconin the ActionBarand if everything worked it should connect to your Wear-Emulator.

再次打开Android磨损配套应用,然后单击watch-icon动作条,如果一切正常,应该连接到你的耐磨模拟器。

Result image

结果图

And, as previously said, this was posted on kennethmascarenhas blog. (props to him)

而且,如前所述,这是在kennethmascarenhas 博客发布的。(给他的道具)

回答by Anthony De Smet

I had a lot of trouble setting this up, but it worked with the following setup.

我在设置它时遇到了很多麻烦,但它适用于以下设置。

My specs

我的规格

macOS Sierra 10.12.4, Android Studio 2.3.2

macOS Sierra 10.12.4,Android Studio 2.3.2

Emulator specs

模拟器规格

Phone emulator: Nexus 5 API 25 -- Android 7.1.1 (Google APIs) Wear emulator: Android Wear Square API 25 -- Android 7.1.1 (Android Wear)

手机模拟器:Nexus 5 API 25 -- Android 7.1.1 (Google APIs) Wear 模拟器:Android Wear Square API 25 -- Android 7.1.1 (Android Wear)

Instructions

指示

  • After creating the proper emulators (and before starting them), download the Android Wear app APK file from http://www.file-upload.net/download-9437648/com.google.android.wearable.app-2.apk.html.
  • Start the phone emulator, wait for it to boot
  • Install the Wear app by using adb: adb -s emulator-5556 install /path/to/download/location/com.google.android.wearable.app-2.apk. Note that 5556 is where my emulator is running, yours might run on a different port. Check the emulator's title window
  • Connect to the device via telnet: telnet localhost 5556. It will complain about credentials, copy the code from the suggested file in the error and in the telnet connection window, execute auth <code>.
  • Still in the telnet window, run redir add tcp:5601:5601
  • Now run the Wear emulator, wait for it to boot
  • Open the Wear app on your phone. I had it crash the first time I tied, just try again. It will tell you bluetooth is unavailable and ask to pair to an emulator.
  • 创建适当的模拟器后(并在启动它们之前),从http://www.file-upload.net/download-9437648/com.google.android.wearable.app-2.apk下载 Android Wear 应用 APK 文件。 HTML
  • 启动手机模拟器,等待它启动
  • 使用 adb: 安装 Wear 应用程序adb -s emulator-5556 install /path/to/download/location/com.google.android.wearable.app-2.apk。请注意,5556 是我的模拟器运行的地方,你的可能运行在不同的端口上。检查模拟器的标题窗口
  • 通过 telnet 连接到设备:telnet localhost 5556。它将抱怨凭据,从错误中的建议文件中复制代码,并在 telnet 连接窗口中,执行auth <code>.
  • 仍然在 telnet 窗口中,运行 redir add tcp:5601:5601
  • 现在运行 Wear 模拟器,等待它启动
  • 打开手机上的 Wear 应用。我第一次绑的时候就崩溃了,再试一次。它会告诉您蓝牙不可用并要求与模拟器配对。

That's it, hope it works for you all because it all seems a bit fragile. Happy coding!

就是这样,希望它对大家有用,因为这一切似乎都有些脆弱。快乐编码!

回答by Manish Menaria

for me, this command worked

对我来说,这个命令有效

adb -s emulator-5556 -d forward tcp:5601 tcp:5601

here are steps to be followed

以下是要遵循的步骤

Open your command prompt and make sure both emulators are recognized with the following command

打开命令提示符并确保使用以下命令识别两个模拟器

ADB devices

Output should be something like this:

输出应该是这样的:

List of devices attached
emulator-5554   device
emulator-5556   device 

if emulator-5556 is your phone emulator than just run this command

如果 emulator-5556 是你的手机模拟器而不是只运行这个命令

adb -s emulator-5556 -d forward tcp:5601 tcp:5601

[Note]

[笔记]

before all this you need to install com.google.android.wearable.app.apkinto your phone emulator

在这一切之前,您需要安装com.google.android.wearable.app.apk到您的手机模拟器中

  • first download apk from this link Apk file link
  • then go to the directory where you downloaded apk file and run this command

    adb -s emulator-5556 install com.google.android.wearable.app.apk
    
  • 首先从此链接下载apk Apk文件链接
  • 然后转到您下载apk文件的目录并运行此命令

    adb -s emulator-5556 install com.google.android.wearable.app.apk
    

here com.google.android.wearable.appwill be the downloaded apk name

这里com.google.android.wearable.app将是下载的 apk 名称

回答by Oleg Gryb

Tried all solutions described above in the following environments:

在以下环境中尝试了上述所有解决方案:

  • Mac OS High Sierra
  • Android API 26, 27 (on both Wear and Phone)
  • Android Studio 3.0.1 and then 3.1.2
  • Wear OS apps com.google.android.wearable.app-2.apk and *-3.apk
  • Mac OS High Sierra
  • Android API 26、27(在 Wear 和手机上)
  • Android Studio 3.0.1 然后是 3.1.2
  • Wear OS 应用 com.google.android.wearable.app-2.apk 和 *-3.apk

Spent the whole day to test all the combinations, but was not able to pass "Emulator Connecting" stage

花了一整天时间测试所有组合,但未能通过“模拟器连接”阶段

enter image description here

enter image description here

Then started reading official Android docs:

然后开始阅读官方 Android 文档:

https://developer.android.com/training/wearables/apps/creating#setting-up-a-phone

https://developer.android.com/training/wearables/apps/creating#setting-up-a-phone

It says explicitly that connecting Wear AVD to Phone AVD is not possible, which is consistent with my experience. Probably it worked for older versions, I don't know.

它明确表示无法将Wear AVD连接到Phone AVD,这与我的经验一致。可能它适用于旧版本,我不知道。

enter image description here

enter image description here

回答by Kenneth Mascarenhas

@Sk1X1 I would comment but unfortunately don't have enough reputation points.

@Sk1X1 我会评论,但不幸的是没有足够的声望点。

Try using:

尝试使用:

adb -s xxxxx forward tcp:5601 tcp:5601

where 'xxxxx' is the device specific name which you get by running the command adb devices. As an example with reference to @reVerse's answer: emulator-5556

其中“xxxxx”是您通过运行命令获得的设备特定名称adb devices。作为参考@reVerse 的答案的示例:emulator-5556

Note: I haven't tested this myself.

注意:我自己没有测试过。

回答by Mahesh N

One more step after Step#6 in the above post is Authentication after Telnet and before redir command

上述帖子中步骤#6 之后的另一步骤是 Telnet 之后和 redir 命令之前的身份验证

Authentication that needs to follow after the telnet command. For example (if your key is oAquOnwIe+eOeBq/ ): auth oAquOnwIe+eOeBq/ Once you are authenticated, you can follow on running the redir command .

需要在 telnet 命令之后进行的身份验证。例如(如果您的密钥是 oAquOnwIe+eOeBq/ ): auth oAquOnwIe+eOeBq/ 通过身份验证后,您可以继续运行 redir 命令。

If this is not done, you get the error "Android Console: Authentication required Android Console: type 'auth ' to authenticate Android Console: you can find your in '/home//.emulator_console_auth_token'

如果不这样做,您会收到错误“Android 控制台:需要身份验证的 Android 控制台:键入 'auth' 以对 Android 控制台进行身份验证:您可以在 '/home//.emulator_console_auth_token' 中找到您的