简体   繁体   English

如何将 adb 与 Memu / Bluestacks / Nox App Player 等模拟器一起使用

[英]How to use adb with emulator like Memu / Bluestacks / Nox App Player

I want to use adb with an android emulator.我想将adb与 android 模拟器一起使用。 Can I fake a USB connection or how is this possible ?我可以伪造 USB 连接,或者这怎么可能?

Emulator is rooted , USB-Debugging Option is On模拟器已rootUSB调试选项已打开

I also tried via apps like adbWireless but I get host has failed to respond (10060) error.我也尝试通过像 adbWireless 这样的应用程序,但我得到主机未能响应 (10060)错误。

Do I always need a USB-connection for initializing?我是否总是需要 USB 连接进行初始化? How is it possible to connect adb with an emulator?如何将adb与模拟器连接?

I'm using Memu version 2.3 and the port used to connect it to Android studio is 21503. Navigate to your sdk's platformtools directory and execute the following in cmd.If it fails try to execute it again.我使用的是 Memu 2.3 版,连接 Android studio 的端口是 21503。导航到你的 sdk 的 platformtools 目录并在 cmd 中执行以下命令。如果失败尝试再次执行它。 You can also install samsung USB driver and try again.您也可以安装三星 USB 驱动程序并重试。

adb connect localhost:21503

I have solved by Following steps:我已经通过以下步骤解决了:

Go to Memu Installation Directory: (In My Case D:\\Program Files\\Microvirt\\MEmu)转到 Memu 安装目录:(在我的情况下 D:\\Program Files\\Microvirt\\MEmu)

And then Delete the adb.exe file.然后删除 adb.exe 文件。 It should work fine for you.它应该适合你。

For MEmu, Droid4X and other VirtualBox-based emulators exists very simple way:对于 MEmu、Droid4X 和其他基于 VirtualBox 的模拟器,存在非常简单的方法:

You need forward 5555 port to you host.您需要将 5555 端口转发到您的主机。

For example in Droid4X you open \\vms\\droid4x\\droid4x.vbox in text editor.例如,在 Droid4X 中,您在文本编辑器中打开\\vms\\droid4x\\droid4x.vbox It is just simple xml file.它只是一个简单的 xml 文件。

In section <NAT> you add line:<NAT>部分添加一行:

<Forwarding name="MY_PORT" proto="1" hostip="127.0.0.1" hostport="5565" guestip="10.0.2.15" guestport="5555"/>

You can use not only 5565 port.您不仅可以使用 5565 端口。 It must be uneven and from range 5555-5585 or adb do not auto find your emulator.它必须是不均匀的,并且范围在 5555-5585 之间,否则 adb 不会自动找到您的模拟器。

Save file and start emulator.保存文件并启动模拟器。 Now run adb devices and you see emulator-5564 in list.现在运行adb devices ,你会在列表中看到emulator-5564

You must edit file only on fully stopped emulator or you changes will be overwritten.您只能在完全停止的模拟器上编辑文件,否则您的更改将被覆盖。 It is mean stop not only virtual machine.这不仅意味着停止虚拟机。 You must stop service process too.您也必须停止服务进程。 Usually it called as VBoxSVC.exe or MemuSVC.exe or another *SVC.exe from folder of your emulator.通常它称为VBoxSVC.exeMemuSVC.exe或模拟器文件夹中的另一个*SVC.exe

For Memu you need edit \\MEmu\\MemuHyperv VMs\\MEmu\\MEmu.memu .对于 Memu,您需要编辑\\MEmu\\MemuHyperv VMs\\MEmu\\MEmu.memu All others stay same.所有其他人保持不变。

In my case this command line didn't work for me在我的情况下,这个命令行对我不起作用

adb connect localhost:21503

Changing localhost to 127.0.0.1 solved itlocalhost更改为127.0.0.1解决了它

adb connect 127.0.0.1:21503

Ok, here is a step-by-step guide for MEmu emulator.好的,这是 MEmu 模拟器的分步指南。

Download and install adbWireless app into emulator (google "adbwireless xda", I can not insert more than 2 links in this post).下载并安装 adbWireless 应用程序到模拟器(谷歌“adbwireless xda”,我不能在这篇文章中插入超过 2 个链接)。 After that, you will need to setup a network bridge, do exactly as written here, and restart your computer: MEmu bridge之后,你需要设置一个网桥,完全按照这里写的做,然后重启你的电脑: MEmu桥

Then open emulator, activate USB debugging, run adbwireless, press the button.然后打开模拟器,激活USB调试,运行adbwireless,按下按钮。 You should see the IP adress, starting from "192.168".您应该会看到 IP 地址,从“192.168”开始。 If it does not - you made something wrong.如果没有 - 你做错了什么。

Run the command shell with administrator privilages.以管理员权限运行命令 shell。 Navigate with it to the folder with adb (in my case it is "D:\\Program Files\\Microvirt\\MEmuHyperv" or add this to system Path variable).使用它导航到带有 adb 的文件夹(在我的情况下它是“D:\\Program Files\\Microvirt\\MEmuHyperv”或将其添加到系统路径变量中)。 Remebber the IP from adbwireless, then in shell ececute a command adb connect your_ip , in my case it was 192.168.0.101.记住来自 adbwireless 的 IP,然后在 shell ececute 命令adb connect your_ip ,在我的情况下是 192.168.0.101。 The shell will notify you: connected to 192.168.0.101:5555 . shell 会通知你: connected to 192.168.0.101:5555 Then execute adb devices , so you should see the list of connected devices.然后执行adb devices ,所以你应该看到连接的设备列表。 Congratulations, you are connected to MEmu using adb.恭喜,您已使用 adb 连接到 MEmu。

There are more ways to setup connection at this post , but it is in russian. 这篇文章有更多设置连接的方法,但它是俄语的。

  • Download/unzip MEmu HyperV Tool下载/解压MEmu HyperV 工具
  • Move files inside the extracted folder to: %PROGRAMFILES%\\Microvirt\\MemuHyperV将解压后的文件夹内的文件移动到:%PROGRAMFILES%\\Microvirt\\MemuHyperV
  • Install a host only networking adapter using driver 'MEmuNetFit.inf' in above folder Start > Control Panel > Device Manager > Network Adapters > [menu at the top of window] > Action > Install Legacy Hardware > Next > [o] Install Hardware I manually - select from a list > Next > [x] Network adapters > Have Disk > Browse... > %PROGRAMFILES%\\Microvirt\\MEmuHyperV\\MEmuNetFit.inf使用上面文件夹中的驱动程序“MEmuNetFit.inf”安装仅主机网络适配器开始>控制面板>设备管理器>网络适配器>[窗口顶部的菜单]>操作>安装旧硬件>下一步>[o]安装硬件I手动 - 从列表中选择 > Next > [x] Network adapters > Have Disk > Browse... > %PROGRAMFILES%\\Microvirt\\MEmuHyperV\\MEmuNetFit.inf
  • Bridge the network adapters Start > Control Panel > Network and Sharing Center > [links on the left side of the window] > Change adapter settings > [click host only adapter and your main internet one while holding ctrl and right click] > bridge connections桥接网络适配器开始 > 控制面板 > 网络和共享中心 > [窗口左侧的链接] > 更改适配器设置 > [在按住 ctrl 并右键单击的同时单击仅主机适配器和主 Internet 适配器] > 桥接连接
  • Close VM and open 'MEmuHyperV.exe' in the 'MEmuHyperV' folder.关闭 VM 并打开“MEmuHyperV”文件夹中的“MEmuHyperV.exe”。 We're going to be connecting the VM to the adapter we created in the following steps.我们将把 VM 连接到我们在以下步骤中创建的适配器。
  • [Right-Click the VM] > Settings > Network > Adapter 2 Removing adapter #1 breaks the VM [右键单击 VM] > 设置 > 网络 > 适配器 2 移除适配器 #1 会破坏 VM
  • Enable adapter, select connected to 'Host-Only Adapter' and select Name: 'MEmuHyperV Host-Only Ethernet Adapter'启用适配器,选择连接到“仅主机适配器”并选择名称:“MEmuHyperV 仅主机以太网适配器”
  • Apply settings and close MEmuHyperV应用设置并关闭 MEmuHyperV
  • navigate to C:\\Program Files\\Microvirt\\MEmu\\adb.exe and launch command fro there.导航到 C:\\Program Files\\Microvirt\\MEmu\\adb.exe 并从那里启动命令。
  • Run adb connect 127.0.0.1:21503.运行 adb connect 127.0.0.1:21503。

First of all you should find configuration file of specific emulator's VM.首先你应该找到特定模拟器虚拟机的配置文件。 eg Memu's configuration vm's file is located near ~ C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEMU_NAME\\MEMU_NAME.memu .例如,Memu 的配置C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEMU_NAME\\MEMU_NAME.memu文件位于 ~ C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEMU_NAME\\MEMU_NAME.memu Secondly, as said in 1st answer, in section you add line:其次,如第一个答案所述,在部分中添加行:

<Forwarding name="ADB" proto="1" hostip="127.0.0.1" hostport="21743" guestip="10.0.2.15" guestport="5555"/>

Take the value of hostport , here it is 21743 .hostport的值,这里是21743

Third step is to use adb from MEmuHyperv C:\\Program Files\\Microvirt\\MEmuHyperv\\adb.exe .第三步是使用来自 MEmuHyperv C:\\Program Files\\Microvirt\\MEmuHyperv\\adb.exe One of possible solutions for this is to open cmd, then to cd to MEmuHyperv's folder and work from there.对此可能的解决方案之一是打开 cmd,然后 cd 到 MEmuHyperv 的文件夹并从那里开始工作。

As MEmuHyperv is now separate project, you can download it from here http://www.memuplay.com/blog/2016/08/08/memuhyperv-tool/由于 MEmuHyperv 现在是单独的项目,您可以从这里下载它http://www.memuplay.com/blog/2016/08/08/memuhyperv-tool/

For Nox App Player, the port is 62001 .对于 Nox App Player,端口为62001

$ adb connect 127.0.0.1:62001
connected to 127.0.0.1:62001

$ adb devices
List of devices attached
127.0.0.1:62001 device

$ adb shell
root@android:/ #

If it does not work, please turn on "USB Debugging" first:如果还是不行,请先打开“USB调试”:

  1. Start Nox App Player.启动 Nox 应用程序播放器。
  2. Go to "Settings" -> "About tablet".转到“设置”->“关于平板电脑”。
  3. Tap (click) "Build number" 7 times, until it says:点击(单击)“版本号”7 次,直到它显示:

    Developer mode has been enabled.开发者模式已启用。

  4. Go back to the previous screen.返回上一屏幕。
  5. Go to "Developer options".转到“开发人员选项”。
  6. Turn on "USB debugging".打开“USB调试”。
  7. Restart Nox App Player.重新启动 Nox 应用程序播放器。

Resources资源

FindEmulatorPort Used to find the android emulator adb port and automatically connect, such as Tencent mobile assistant, Netease MuMu、BlueStacks、Nox App Player and so on. FindEmulatorPort用于寻找安卓模拟器adb端口并自动连接,如腾讯手机助手、网易MuMu、BlueStacks、Nox App Player等。 download from: https://gitee.com/tp7309/TTEmulatorPortFinder/repository/archive/master.zip下载地址: https : //gitee.com/tp7309/TTEmulatorPortFinder/repository/archive/master.zip

python emulator_port.py

copy adb.exe and all files you find in it's folder in the android SDK , used by your Studio, than past it to memu folder to replace old memu adb.复制 adb.exe 以及您在 Studio 使用的 android SDK 文件夹中找到的所有文件,然后将其传递到 memu 文件夹以替换旧的 memu adb。 that's it.就是这样。

I am using a memu with Android 7 and after a lot of effort I realized that on this version of Android you have to change the port to 21513 ( memu version 7.2.7 / Android 7.1 )我在 Android 7 上使用 memu,经过很多努力,我意识到在这个版本的 Android 上你必须将端口更改为 21513(memu 版本 7.2.7 / Android 7.1)

adb connect 127.0.0.1:21513

I hope you find it useful我希望你觉得它有用

This method works well on Xamarin and Android Studio .此方法在XamarinAndroid Studio上运行良好。

Tested with NOX v7NOX v7测试

  1. Go to nox installation folder and delete or rename both adb.exe and nox_adb.exe .转到 nox 安装文件夹并删除重命名adb.exenox_adb.exe
  2. Go to Environment Variable and open Path then add yor platform-tools folder from your SDK.转到Environment Variable并打开Path,然后从您的 SDK 添加您的platform-tools文件夹。 For example: D:\\android-sdk\\platform-tools例如: D:\\android-sdk\\platform-tools
  3. Then Go to platform-tools folder and make a copy from adb.exe and rename it to nox_adb.exe .然后转到platform-tools文件夹并从adb.exe复制一份并将其重命名为nox_adb.exe so we have both adb.exe and nox_adb.exe in platform-tools .所以我们在platform-tools 中adb.exenox_adb.exe

After performing these simple steps, it is better to restart the PC.执行完这些简单的步骤后,最好重新启动 PC。

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

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