有没有办法通过命令行启动给定的avd
并通过adb
注册?
我也希望让模拟器无头启动。
我正在寻找这个快速运行测试。
对于寻找非无头命令行启动的其他人:
/Applications/Genymotion.app/Contents/MacOS/player --vm-name "xxxx"
获取vms列表:
$ VBoxManage list vms
"Galaxy Nexus - 4.2.2 - API 17 - 720x1280" {56d8e3aa-ecf8-483e-a450-86c8cdcedd35}
其中xxxx可以是name或id:
/Applications/Genymotion.app/Contents/MacOS/player --vm-name 56d8e3aa-ecf8-483e-a450-86c8cdcedd35
/Applications/Genymotion.app/Contents/MacOS/player --vm-name "Galaxy Nexus - 4.2.2 - API 17 - 720x1280"
你可以用正常的进程kill杀死它:
ps | grep "Genymotion\.app/Contents/MacOS/player" | awk '{print $1}' | xargs kill
这是一个更好的程序。这将需要第一次手动启动,但之后,你将获得一个快速的genymotion,几秒钟内。以下脚本已在macos x上测试过。他们可能需要更多的Linux工作。
首先,通常通过genymotion应用程序启动genymotion模拟器。然后,从虚拟框中获取其sha1:
VBoxManage list vms
然后,从命令行获取它的快照:
#script genymotion-save.sh
VM=6a5d9245-b751-47aa-b38d-989c5f1a9cfb
echo "VM is \"$VM\""
VBoxManage snapshot $VM take snap1
然后你可以使用这个脚本检测它的ip(它的大多数复杂性来自mac地址转换):
#script genymotion-detect-ip.sh
VM=6a5d9245-b751-47aa-b38d-989c5f1a9cfb
#find mac of vm
#http://stackoverflow.com/questions/10991771/sed-to-insert-colon-in-a-mac-address
# Update arp table
for i in {1..254}; do ping -c 1 192.168.56.$i 2&>1; done
MAC=`VBoxManage showvminfo "$VM" | grep MAC | grep Host | awk -F ":" '{print $3}' | cut -c 2-13`
#echo "MAC is $MAC"
MAC=`echo $MAC | sed -e 's/\([0-9A-Fa-f]\{2\}\)/\1:/g' -e 's/\(.*\):$/\1/' | tr '[:upper:]' '[:lower:]'`
#echo "MAC is $MAC"
# Find IP: substitute vname-mac-addr with your vm's mac address in ':' notation
IP=`arp -a | sed "s/ \(.\):/ 0\1:/" | sed "s/:\(.\):/:0\1:/g"|sed "s/:\(.\):/:0\1:/g"|sed "s/:\(.\)$/:0\1/"|grep $MAC`
#echo "IP is $IP"
IP=`echo $IP | cut -d "(" -f2 | cut -d ")" -f1`
echo $IP
现在,您已经拥有从命令行启动vm快照并通过adb(使用root)连接到它的所有功能。您可以使用此脚本执行此操作:
# script genymotion-start.sh
VM=6a5d9245-b751-47aa-b38d-989c5f1a9cfb
echo "VM is \"$VM\""
VBoxManage snapshot $VM restore snap1 &
VBoxHeadless -s $VM &
IP=`./genymotion-detect-ip.sh`
echo $IP
#adb tcpip 5555
adb connect $IP:5555
#restart adb as root to allow powering it off
#root mode is generally what we want from a headless emulator (to download emma files for instance)
adb root
adb connect $IP:5555
最后,您还可以使用脚本正确关闭模拟器:
#script genymotion-stop.sh
IP=`./genymotion-detect-ip.sh`
adb root
adb connect $IP:5555
adb shell reboot -p &
这仍然是很多脚本,但它工作正常,并以一种方便的方式控制genymotion模拟器。
让我们希望genymobile可以在以后的版本中使这个前夕更容易。
我在Ubuntu上运行,我修改了Snicolas's answer并上传为Gist:https://gist.github.com/guneysus/410bb0e6b56d6f228555
主要区别是:
geny_devices.sh
中定义设备并使用此文件轻松选择VM:```
# script geny_devices.sh
s3_43="e63063e8-a922-4832-8bcf-05362c3a1c9a"
nexus_44="45287ed9-2d5e-49a5-a0f9-82c29e7cc4b3"
# Samsung Galaxy S3 - 4.3 - API 18 - 720x1280" {e63063e8-a922-4832-8bcf-05362c3a1c9a}
# "Google Nexus 7 - 4.4.4 - API 19 - 800x1280" {45287ed9-2d5e-49a5-a0f9-82c29e7cc4b3}
#script geny_snap.sh
source geny_devices.sh
VM=${s3_43}
# Hopefully performance improvement ;) Not really necessary
# for in in {1..254};
# do ping -c 192.168.56.$1 2&>1;
# done
MAC=`VBoxManage showvminfo ${VM} | grep MAC | awk -F ":" '{print $3}' | cut -c 2-13`
# echo "MAC is ${MAC}"
# On linux data returned from arp -a is like
# ? (192.168.56.101) at 08:00:27:b0:7f:38 [ether] on vboxnet0
# ? (192.168.0.1) at 9e:a9:e4:d5:43:5b [ether] on eth2
# Find IP with
IP=`arp -a | egrep vboxnet|grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"`
# echo "IP is $IP"
IP=`echo $IP | cut -d "(" -f2 | cut -d ")" -f1`
# echo $IP|xclip
# echo -e "[OK] IP \t:\t ${IP}
# IP exported as global variable and to the clipboard."
echo $IP
# script geny_save.sh
source geny_devices.sh
VM=${s3_43}
echo "VM is \"$VM\""
VBoxManage snapshot $VM restore snap1 &
# script geny_start.sh
source geny_devices.sh
VM=${s3_43}
echo "VM is \"$VM\""
VBoxManage snapshot $VM restore snap1 &
VBoxHeadless -s $VM &
IP=`./geny_ip.sh`
echo ">>>>>>" $IP
adb tcpip 5555
adb connect $IP:5555
#restart adb as root to allow powering it off
#root mode is generally what we want from a headless emulator (to download emma files for instance)
adb root
adb connect $IP #:5555
#script geny_stop.sh
IP=`./geny_ip.sh`
adb root
adb connect $IP:5555
adb shell reboot -p &
```
感谢@k的回答,我能够在Mac上启动Geny运动模拟器,但我不得不对Mac OS Sierra 10.12.6和GenyMotion 2.10.0进行一些更改。
/Applications/Genymotion.app/Contents/MacOS/player.app/Contents/MacOS/player --vm-name "xxxx"
并杀死它
ps | grep "/Applications/Genymotion\.app/Contents/MacOS/player\.app/Contents/MacOS/player" | awk '{print$1}' | xargs kill
希望它可以帮助某人。
如果有人不了解环境变量,寻找非无头并使用Windows,您可以通过运行以下命令来检查命令,其中安装了VirtualBox:
C:\Program Files\Oracle\VirtualBox list vms
然后,您可以使用以下内容运行所需的设备:
C:\Program Files\Genymobile\Genymotion\tools player --vm-name "Google Nexus 4"
当然,将这些路径放在环境变量上是更好的方法。
从命令行启动genymotion的命令 -
player --vm-name Nexus_4
如果玩家尚未添加到路径中,请使用〜/ .bash_profile中的以下命令将其添加到路径中
export PATH=/Applications/Genymotion.app/Contents/MacOS/:$PATH
当连接多个设备时,使用'adb -s'将命令重定向到特定设备一旦模拟器运行,它们将列在adb设备下
例:
adb devices
List of devices attached
192.168.56.101:5555 device
当连接多个设备时,发送命令以在Android设备上单击菜单键:
adb -s 192.168.56.101:5555 shell input keyevent KEYCODE_MENU