How can I script genymotion emulator to launch a given avd, headless?

前端 未结 7 678
心在旅途
心在旅途 2020-12-12 15:43

Is there any way to launch by command line a given avd and have it registered via adb ?

I would also prefer to get the emulator l

相关标签:
7条回答
  • 2020-12-12 16:12

    Here is a better procedure. It will require a first manual launch, but afterwards, you will get a blazing fast genymotion, up within seconds. The following scripts have been tested on macos x. They may need some more work for linux.

    First, launch genymotion emulator normally via genymotion app. Then, get its sha1 from Virtual box :

    VBoxManage list vms

    Then, take a snapshot of it from command line :

    #script genymotion-save.sh
    VM=6a5d9245-b751-47aa-b38d-989c5f1a9cfb
    
    echo "VM is \"$VM\""
    VBoxManage snapshot $VM take snap1 
    

    Then you can detect its ip using this script (most of its complexity comes from mac address conversion):

    #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
    

    Now, you have all you need to start up the vm's snapshot from the command line and connect to it via adb (using root). You can do it with this script :

    # 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
    

    And finally you can also use a script to shutdown the emulator properly :

    #script genymotion-stop.sh 
    IP=`./genymotion-detect-ip.sh`
    
    adb root
    adb connect $IP:5555
    adb shell reboot -p &
    

    This is still a lot of scripting but it works fine and controls the genymotion emulator in an handy way.

    Let's hope genymobile can make this eve easier in future releases.

    0 讨论(0)
  • 2020-12-12 16:17

    In distros GNU/Linux

    It's easy

     cd genymotion/
    

    In this folder,you need find file player

    Now you need the device name

    In your terminal, write this command,replacing NameDevice for your device name

     ./player --vm-name <NameDevice>
    

    And now your emulator started

    In GNU/Linux you can create access in the menu

    Good Luck

    0 讨论(0)
  • For others looking for non-headless command line startup:

    /Applications/Genymotion.app/Contents/MacOS/player --vm-name "xxxx"
    

    Get a list of vms:

    $ VBoxManage list vms
    "Galaxy Nexus - 4.2.2 - API 17 - 720x1280" {56d8e3aa-ecf8-483e-a450-86c8cdcedd35}
    

    Where xxxx can be either the name or the 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"
    

    You can kill it with a normal process kill:

    ps | grep "Genymotion\.app/Contents/MacOS/player" | awk '{print $1}' | xargs kill
    
    0 讨论(0)
  • 2020-12-12 16:19

    Just in case anyone doesn't know about environment variables, looking for a non-headless and using Windows, you can check the commands by running the following command where it's installed your VirtualBox:

    C:\Program Files\Oracle\VirtualBox list vms
    

    Then you can run your desired device with something like the following:

    C:\Program Files\Genymobile\Genymotion\tools player --vm-name "Google Nexus 4"
    

    Of course, put that paths on your environment variable would be the better approach.

    0 讨论(0)
  • 2020-12-12 16:22

    Command to launch genymotion from command line -

    player --vm-name Nexus_4
    

    if player is not already added to path, add it to path using below command in your ~/.bash_profile

    export PATH=/Applications/Genymotion.app/Contents/MacOS/:$PATH
    

    When more than one device is connect use 'adb -s' is used to redirect commands to particular device Once emulator is running they will be listed under adb devices

    Example:

    adb devices
    List of devices attached 
    192.168.56.101:5555 device
    

    Send command to click on menu key on android device when multiple devices are connected:

    adb -s 192.168.56.101:5555 shell input keyevent KEYCODE_MENU 
    
    0 讨论(0)
  • 2020-12-12 16:27

    Thanks to @k s answer I was able to launch the Geny motion emulator on Mac but I had to make few changes for Mac OS Sierra 10.12.6 and GenyMotion 2.10.0

    /Applications/Genymotion.app/Contents/MacOS/player.app/Contents/MacOS/player --vm-name "xxxx"
    

    and to kill it

    ps | grep "/Applications/Genymotion\.app/Contents/MacOS/player\.app/Contents/MacOS/player" | awk '{print$1}' | xargs kill
    

    Hope it helps someone.

    0 讨论(0)
提交回复
热议问题