I am using Jenkins Pipeline to Checkout,Build and Launch Espresso tests on my emulator before archiving the APK,The problem is that I cannot launch the emulator automatically from Jenkins.However with the same command from Windows command line I am able to run the emulator:
Script
node{
// Previous stages and some magic...
stage('Test') {
bat "D:\\Tools\\Dev\\sdk\\tools\\emulator.exe -avd Nexus_5X_Marshmallow_API_23"
}
}
Screenshots of Jenkins Logs and same command on windows
Does anybody have an idea about what can be done to fix this issue ?
You shuold try running your command with single quotation marks:
bat 'D:\\Tools\\Dev\\sdk\\tools\\emulator.exe -avd Nexus_5X_Marshmallow_API_23'
I am also not shure if you need to escape your path.
Related
I am using a Android Emulator to run some tests where a need to send some information with adb commands so I created a Pipeline where the first stage is running the emulator with this command in the pipeline
bat 'emulator -avd Pixel_2_Test -no-window -no-audio wait-for-device'
When I use this command the job breaks, I think beacause is a daemon, so I tried to use start in the begin of the command to execut in backgroud, so in the next step I have:
bat 'adb devices'
I have this to see if the emulator is running but never return nothing, only never stop this step. I have to finished the job manually. I don't know if the emulator is really runing on background mode and I dont know why the adb command never stop. Please help me. I dont know how to run this emulator on the pipeline on Windows
Essentially my issue is that when I run emulator -verbose -avd Nexus_5X_API_19 in the command line the emulator starts up with the argument -dns-server = "w,x,y,z" where w,x,y,z are 4 ip addresses for DNS servers. When I run ipconfig /all I only see x,y,z listed as my valid DNS servers in Windows. Because of this odd first DNS server, I am unable to access the internet within the emulator. When I run the emulator with emulator -verbose -avd Nexus_5X_API_19 -dns-server "x,y,z" everything works fine.
But now I want to be able to run my app from within Android Studio 2.2.3 with the corrected DNS servers. So does anyone know how to specify the emulator command line arguments within Android Studio (similar to this answer for the older Eclipse based version: https://stackoverflow.com/a/4736518/1088659), or how to set the default DNS for the emulator to start with?
Unfortunately, as of 3.0.1, this isn't possible. They removed adding additional arguments for emulators launched from Android Studio. Until they add it back in, starting the emulator from the command line (as you showed) is the only option.
You can track this issue here: https://issuetracker.google.com/issues/37071385
If you are on MacOS or Linux, you could rename the Android Emulator executable to something else (say emulator-binary) and create a script with the actual emulator name (emulator) in its place, that calls the executable with the -dns-server parameter.
Here are the steps required:
Find the path where the Android SDK is located in your system. This answer will help you find it.
cd <your-SDK-path>/emulator.
Rename the original executable: mv emulator emulator-binary.
Finally, create an emulator shell script named emulator with the following contents:
<your-SDK-path>/emulator-binary -dns-server "8.8.8.8,8.8.4.4" $#
Unfortunately, I ran into the same issue. I wrote a simple script that pulls the DNS address from settings automatically. Script was written for MacOS, but should work for Linux just the same. Note: You may need to change the path to the Android Emulator script.
#!/bin/bash
set -m
dns=$(grep "nameserver" /etc/resolv.conf | grep "\." | awk '{split($0,a," "); print a[2]}')
echo "Running emulator with DNS address: $dns"
~/Library/Android/sdk/emulator/emulator -avd $1 -dns-server $dns -no-snapshot-load &>/dev/null &
disown
You just need to give it your emulator name (note: spaces become underscores), e.g.:
runemu Pixel_4_API_30
where "runemu" is what I named the script on my machine.
I'm trying to start the emulator, on a mac(sierra) jenkins slave like this:
/Users/username/Library/Android/sdk/tools/emulator -avd Nexus_5_API_25 -wipe-data
And the build hangs. It starts the emulator, but it does not proceed with the build.
I guess I need to start it as a background process, which should be something like this:
/Users/username/Library/Android/sdk/tools/emulator -avd Nexus_5_API_25 -wipe-data $
but I get an error:
invalid command-line parameter: $.
What would be the correct way of starting the emulator without blocking the build?
edit: I would like to solve this without installing the android emulator plugin(I have no rights, or permission to install it)
I am try to launch an android emulator from jenkins.
I have written a batch file as follows:
cd E:\android-sdk\tools
emulator.exe -avd "AVD" -wipe-data
I execute this batch file from jenkins. But it does not launch the emulator.
I have also tried launching it from python as follows:
bash = "E:\\android-sdk\\tools\\emulator"
print "executing: " + bash
f_handle = open('test_output_launch.txt','w+')
process = subprocess.Popen([bash, '-avd', 'AVD'])
But the latter gives an error 'PANIC: Could not open: AVD'.
Where as when I run the batch file normally without jenkins, everything works perfectly.
I need to launch the AVD, install apk on it, and run some automated tests via jenkins. Please help!!
I think, it should be permission issue. Try running the jenkins client as admin.
For Python, change your subprocess call to
process = subprocess.Popen(['emulator.exe', '-avd', 'AVD'], cwd=bash)
You can try your script in command line first.
It finally worked with 'Android Emulator Plugin' of jenkins.
I've wrote a script test.sh for android automation testing, here require start emulator each time
PATH="$PATH:/home/xxx/tool/jdk1.6.0_34/bin:/home/xxx/tool/android-sdk-linux/tools:"
emulator -avd avd22
I put test.sh in crontab, but looks emulator can't come up in crontab, but manually I execute test.sh, all things work fine.
fix it by adding following command before emulator command
export DISPLAY=:0 && emulator -avd avd22