Run AndroidTest on Android Emulator In Docker - android

I saw some links and posts about running AndroidTest in Docker. Like:
https://dzone.com/articles/running-android-tests-in-docker
https://github.com/ksoichiro/android-tests/tree/master/docker-emulator
And some more. However, they all seem inappropriate for AndroidTest in CI, since they require an actual VM, or simply they are too old.
I tried the following lines Docker Image (Partial):
RUN /opt/adk/tools/bin/sdkmanager "emulator" "build-tools;${BUILD_TOOLS}" "platforms;${ANDROID_PLATFORM}" "system-images;${ANDROID_PLATFORM};google_apis;armeabi-v7a" \
&& echo no | /opt/adk/tools/bin/avdmanager create avd -n "Android" -k "system-images;${ANDROID_PLATFORM};google_apis;armeabi-v7a" \
And then I run the emulator using:
/opt/adk/emulator/emulator #Android -writable-system -nocache -no-snapstorage &
However, when trying to run connectedAndroidTest there were some weird exceptions, like:
Caused by: com.android.ddmlib.InstallException: Unknown failure: Error: Could not access the Package Manager. Is the system running?
Or, if I try to manually install the test APK, and run am instrument:
android.util.AndroidException: Can't connect to activity manager; is the system running?
So my question: Is anyone is running AndroidTest on emulator as part of the CI on docker? Means, an image that you just need to mount your project and run gradle connectedAndroidTest, and everything works? Is there a working example for that?

I run AndroidTest on emulator as part of the CI on docker using this image: https://hub.docker.com/r/chrisss404/android-emulator
The problem you might encounter is that hardware acceleration is not available on your host because of missing nested KVM (just a guess, but that was the problem I was facing). In this case you have to use software rendering, which can take a significant amount of time.
With software rendering, the startup takes about 40 minutes until the emulator is usable (on my host). However, then you can run the instrumentation tests as usual in an acceptable timeframe.

Related

black screen in Android emulator in Ubuntu VM in Windows 7

I built AOSP 5.1.0_r5 (LMY47O) with no modifications done to the source code. The build process ends with "success" and I get bunch of *.img files in out/target/product/deb. Sadly, executing emulator -verbose produces the generic emulator window with an empty screen and following output in the console. I see nothing that would explain the black screen. (I am looking at the black screen for tens of minutes, hence I doubt it is "merely very slow.")
My environment is Ubuntu 16.04 running in VirtualBox under Windows 7, no IDE involved.
Just an assumption. You have a line in your output: Failed to create Context 0x3005
Could not initialize emulated framebufferemulator: Can't start OpenGLES renderer? It seems that this is the cause of the problem. Could you please install the following libraries sudo apt-get install mesa-utils-extra and run your emualator once again?
P.S. What is the target deb? Try to build the AOSP using a recommended target, e.g., aosp_arm-eng.

Jenkins running on headless linux aws with xvfb getting error for the connectedAndroidTest espresso

Giving Error on jenkins while running android espresso test.
My server is headless linux aws, and i am using xvfb to run android emulator virtually and want to run test cases.
i have already create emulator with command line
android create avd --force -n nexus4-emulator2 -t "Google Inc.:Google APIs:18" --abi default/armeabi-v7a -s "768x1280" --device "Nexus 4" -c 128M
this is creating emulator, first it was giving permission error, but after adding access permission it get resolved.
now some of logs on jenkins is like below
[android] Starting Android emulator
$ /opt/android-sdk-linux//platform-tools/adb -s emulator-5788
wait-for-device shell getprop init.svc.bootanim [android] Emulator
reported that the startup process is 'running'
[android] Attempting to unlock emulator screen
:Chynge:preBuild UP-TO-DATE
Installing APK 'app-debug.apk' on 'nexus4-emulator(AVD) - 4.3.1' for
Chynge:debug Installed on 1 device.
:app:connectedDebugAndroidTest
com.app_positive.LoginTest > loginTest[nexus4-emulator(AVD) - 4.3.1]
[31mFAILED [0m android.support.test.espresso.NoMatchingViewException:
No views in hierarchy found matching: (with id: com.app:id/btn_login
and with text: is "Login with E-Mail" and is displayed on the screen
to the user)
:app:connectedDebugAndroidTest FAILED
What went wrong: Execution failed for task ':app:connectedDebugAndroidTest'.
There were failing tests. See the report at: file:///data/jenkins/workspace/android-ci-tests/client/android/app/build/reports/androidTests/connected/index.html
[Gradle] - Launching build.
Build step 'Invoke Gradle script' changed build result to FAILURE Xvfb
stopping Finished: FAILURE
![Emulator Configuration][see here]![Gradle task configuration][see here] I haven't added command to create emulator or to open it, but Jenkins provides android emulator plugin that do all things like creating emulator, wait to open, launch emulator, i just have to add configuration for it.
finally i got answer, i tried to create emulator on my windows machine with same configuration on Jenkins,and install app on it , it was showing google play service update pop up, and that's the reason, runner unable to find view on screen, as pop up don't allow to run the app, query of creating emulator is like
path upto android_sdk_tools>> android create avd --force -n emualator_29 -t android-23 --abi google_apis/armeabi-v7a -s "768x1280" --device "Nexus 4" -c 128M
just by taking new version 23, some ideal screen resolution, and one more only armeabi-v7a runs on headless machine...it works for me..thank you..
I haven't used ever Jenkins, but I used Travis CI for building my Github projects. I know that can after installing plugin read Travis configuration files with .yml extensions.
Here's my configuration of Android emulator
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi armeabi-v7a --sdcard 200M
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- sleep 10
- adb shell settings put global window_animation_scale 0 &
- adb shell settings put global transition_animation_scale 0 &
- adb shell settings put global animator_duration_scale 0 &
- adb shell input keyevent 82 &
From: https://github.com/piotrek1543/LocalWeather/blob/master/.travis.yml
As you can see after creating an emulator instance (first line), I'm executing android-wait-for-emulator as loading the virtual device may take more than few minutes and Espresso test may start before emulator woulb in idle. Also remember to turn off animation and unlock the screen (tha last line).
Try to write similar script.
EDIT: As you're using headless server uncheck this options:
show emulator window
Running on headless build machines
If you have build slaves which are
headless (e.g. Linux servers that don't have a graphical user
interface), you can still run an Android Emulator even although, by
default, the emulator does require a graphical environment.
Just untick the "Show emulator window" configuration option in your
job configuration. This is the equivalent of using the emulator's
"-no-window" command-line option.
From: https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin
use emulator snapshots
Similarly, snapshot support does not fully function for Android 4.0
until SDK Tools r15. An initial snapshot can be created, but
subsequently loading from that snapshot will crash the emulator
immediately. Earlier Android versions are not affected, i.e. you can
still use snapshots with Android 3.2 and earlier. Upgrading to SDK
Tools r15+ should fix this.
As a workaround, you can also uncheck "Use emulator snapshots" in any
jobs where you are seeing problems.
From: https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin
The same solution is described on that screen:
From http://blog.zuehlke.com/en/configure-your-android-project-on-jenkins/
EDIT2: Read this article: https://www.cloudbees.com/blog/continuous-integration-mobile-apps-jenkins-android-builds and notice:
Notice that you can add some additional scripts to your emulator, try to use mine without first line.
Hope it will help

com.android.builder.testing.ConnectedDevice > hasTests[test(AVD) - 5.0] FAILED

i have try my best to test my android project with gradle on, but failed.
can you help me with it?Thank you.
This is my project:
https://github.com/SnowdreamFramework/android-log
and i provide my error log with the attachment.
[0K$ echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
Android 5.0 is a basic Android platform.
Do you wish to create a custom hardware profile [no]Created AVD 'test' based on Android 5.0, ARM (armeabi-v7a) processor,
with the following hardware config:
hw.cpu.model=cortex-a8
hw.lcd.density=240
hw.ramSize=512
vm.heapSize=48
travis_time:end:0d68df50:start=1416651329874810477,finish=1416651333337412612,duration=3462602135
[0Ktravis_fold:end:before_script.4
[0Ktravis_fold:start:before_script.5
[0Ktravis_time:start:15d80c70
[0K$ emulator -avd test -no-skin -no-audio -no-window &
travis_time:end:15d80c70:start=1416651333347425441,finish=1416651333353869405,duration=6443964
[0Ktravis_fold:end:before_script.5
[0Ktravis_fold:start:before_script.6
[0Ktravis_time:start:01e4ff4d
[0K$ android-wait-for-emulator
Creating filesystem with parameters:
Size: 69206016
Block size: 4096
Blocks per group: 32768
Inodes per group: 4224
Inode size: 256
Journal blocks: 1024
Label:
Blocks: 16896
Block groups: 1
Reserved block group size: 7
Created filesystem with 11/4224 inodes and 1302/16896 blocks
Waiting for emulator to start
Failed to Initialize backend EGL display
emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Waiting for emulator to start
Emulator is ready
travis_time:end:01e4ff4d:start=1416651333362333914,finish=1416651367641918931,duration=34279585017
[0Ktravis_fold:end:before_script.6
[0Ktravis_fold:start:before_script.7
[0Ktravis_time:start:1f99871a
[0K$ adb shell input keyevent 82 &
travis_time:end:1f99871a:start=1416651367652665093,finish=1416651367659437822,duration=6772729
[0Ktravis_fold:end:before_script.7
[0Ktravis_time:start:0e5eb826
[0K$ TERM=dumb gradle build connectedCheck
Download https://repo1.maven.org/maven2/com/android/tools/build/gradle/0.13.3/gradle-0.13.3.pom
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-gradle/4.11/proguard-gradle-4.11.pom
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-parent/4.11/proguard-parent-4.11.pom
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint/23.1.3/lint-23.1.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/builder/0.13.3/builder-0.13.3.pom
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-base/4.11/proguard-base-4.11.pom
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/23.1.3/lint-checks-23.1.3.pom
Download https://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/4.2.2/ecj-4.2.2.pom
Download https://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/23.1.3/ddmlib-23.1.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.13.3/builder-model-0.13.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/sdk-common/23.1.3/sdk-common-23.1.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/23.1.3/manifest-merger-23.1.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.13.3/builder-test-api-0.13.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/common/23.1.3/common-23.1.3.pom
Download https://repo1.maven.org/maven2/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom
Download https://repo1.maven.org/maven2/org/sonatype/oss/oss-parent/7/oss-parent-7.pom
Download https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.pom
Download https://repo1.maven.org/maven2/com/android/tools/sdklib/23.1.3/sdklib-23.1.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-api/23.1.3/lint-api-23.1.3.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-parent/4.0/asm-parent-4.0.pom
Download https://repo1.maven.org/maven2/org/ow2/ow2/1.3/ow2-1.3.pom
Download https://repo1.maven.org/maven2/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.pom
Download https://repo1.maven.org/maven2/kxml2/kxml2/2.3.0/kxml2-2.3.0.pom
Download https://repo1.maven.org/maven2/com/google/guava/guava/15.0/guava-15.0.pom
Download https://repo1.maven.org/maven2/com/google/guava/guava-parent/15.0/guava-parent-15.0.pom
Download https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.pom
Download https://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/23.1.3/layoutlib-api-23.1.3.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1.1/httpcomponents-client-4.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/project/4.1.1/project-4.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1/httpcomponents-client-4.1.pom
Download https://repo1.maven.org/maven2/com/android/tools/dvlib/23.1.3/dvlib-23.1.3.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/33/commons-parent-33.pom
Download https://repo1.maven.org/maven2/org/apache/apache/13/apache-13.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm/4.0/asm-4.0.pom
Download https://repo1.maven.org/maven2/com/android/tools/external/lombok/lombok-ast/0.2.2/lombok-ast-0.2.2.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.1/httpcomponents-core-4.1.pom
Download https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/5/commons-parent-5.pom
Download https://repo1.maven.org/maven2/org/apache/apache/4/apache-4.pom
Download https://repo1.maven.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/11/commons-parent-11.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/gradle/0.13.3/gradle-0.13.3.jar
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-gradle/4.11/proguard-gradle-4.11.jar
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint/23.1.3/lint-23.1.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/builder/0.13.3/builder-0.13.3.jar
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-base/4.11/proguard-base-4.11.jar
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/23.1.3/lint-checks-23.1.3.jar
Download https://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/4.2.2/ecj-4.2.2.jar
Download https://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/23.1.3/ddmlib-23.1.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.13.3/builder-model-0.13.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/sdk-common/23.1.3/sdk-common-23.1.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/23.1.3/manifest-merger-23.1.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.13.3/builder-test-api-0.13.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/common/23.1.3/common-23.1.3.jar
Download https://repo1.maven.org/maven2/com/squareup/javawriter/2.5.0/javawriter-2.5.0.jar
Download https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.jar
Download https://repo1.maven.org/maven2/com/android/tools/sdklib/23.1.3/sdklib-23.1.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-api/23.1.3/lint-api-23.1.3.jar
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.jar
Download https://repo1.maven.org/maven2/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar
Download https://repo1.maven.org/maven2/com/google/guava/guava/15.0/guava-15.0.jar
Download https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.jar
Download https://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/23.1.3/layoutlib-api-23.1.3.jar
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.jar
Download https://repo1.maven.org/maven2/com/android/tools/dvlib/23.1.3/dvlib-23.1.3.jar
Download https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar
Download https://repo1.maven.org/maven2/org/ow2/asm/asm/4.0/asm-4.0.jar
Download https://repo1.maven.org/maven2/com/android/tools/external/lombok/lombok-ast/0.2.2/lombok-ast-0.2.2.jar
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.jar
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar
Download https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
Download https://repo1.maven.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.jar
Sonatype SNAPSHOT BUILD
GITHUB SNAPSHOT BUILD
Download https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/22/commons-parent-22.pom
Download https://repo1.maven.org/maven2/org/apache/apache/9/apache-9.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
:lib:androidJavadocsJar
:lib:compileLint
:lib:copyReleaseLint UP-TO-DATE
:lib:mergeReleaseProguardFiles
:lib:preBuild
:lib:preReleaseBuild
:lib:checkReleaseManifest
:lib:prepareReleaseDependencies
:lib:compileReleaseAidl
:lib:compileReleaseRenderscript
:lib:generateReleaseBuildConfig
:lib:generateReleaseAssets UP-TO-DATE
:lib:mergeReleaseAssets
:lib:generateReleaseResValues
:lib:generateReleaseResources
:lib:packageReleaseResources
:lib:processReleaseManifest
:lib:processReleaseResources
:lib:generateReleaseSources
:lib:compileReleaseJava
:lib:processReleaseJavaRes UP-TO-DATE
:lib:packageReleaseJar
:lib:compileReleaseNdk
:lib:packageReleaseJniLibs UP-TO-DATE
:lib:packageReleaseLocalJar UP-TO-DATE
:lib:packageReleaseRenderscript UP-TO-DATE
:lib:bundleRelease
:lib:assembleRelease
:lib:androidReleaseJar
:lib:androidSourcesJar
:lib:copyDebugLint UP-TO-DATE
:lib:mergeDebugProguardFiles
:lib:preDebugBuild
:lib:checkDebugManifest
:lib:prepareDebugDependencies
:lib:compileDebugAidl
:lib:compileDebugRenderscript
:lib:generateDebugBuildConfig
:lib:generateDebugAssets UP-TO-DATE
:lib:mergeDebugAssets
:lib:generateDebugResValues
:lib:generateDebugResources
:lib:packageDebugResources
:lib:processDebugManifest
:lib:processDebugResources
:lib:generateDebugSources
:lib:compileDebugJava
:lib:processDebugJavaRes UP-TO-DATE
:lib:packageDebugJar
:lib:compileDebugNdk
:lib:packageDebugJniLibs UP-TO-DATE
:lib:packageDebugLocalJar UP-TO-DATE
:lib:packageDebugRenderscript UP-TO-DATE
:lib:bundleDebug
:lib:assembleDebug
:lib:signArchives
:lib:assemble
:lib:lint
Ran lint on variant release: 7 issues found
Ran lint on variant debug: 7 issues found
Wrote HTML report to file:/home/travis/build/SnowdreamFramework/android-log/lib/build/outputs/lint-results.html
Wrote XML report to /home/travis/build/SnowdreamFramework/android-log/lib/build/outputs/lint-results.xml
:lib:check
:lib:build
:lib:compileDebugTestNdk
:lib:preDebugTestBuild
:lib:prepareDebugTestDependencies
:lib:compileDebugTestAidl
:lib:processDebugTestManifest
:lib:compileDebugTestRenderscript
:lib:generateDebugTestBuildConfig
:lib:generateDebugTestAssets UP-TO-DATE
:lib:mergeDebugTestAssets
:lib:generateDebugTestResValues
:lib:generateDebugTestResources
:lib:mergeDebugTestResources
:lib:processDebugTestResources
:lib:generateDebugTestSources
:lib:compileDebugTestJava
:lib:preDexDebugTest
:lib:dexDebugTest
:lib:processDebugTestJavaRes UP-TO-DATE
:lib:validateDebugSigning
:lib:packageDebugTest
:lib:assembleDebugTest
:lib:connectedAndroidTest
Tests on test(AVD) - 5.0 failed: No test results
com.android.builder.testing.ConnectedDevice > hasTests[test(AVD) - 5.0] [31mFAILED [0m
No tests found.
:lib:connectedAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib:connectedAndroidTest'.
> There were failing tests. See the report at: file:///home/travis/build/SnowdreamFramework/android-log/lib/build/outputs/reports/androidTests/connected/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 23.514 secs
travis_time:end:0e5eb826:start=1416651367667280733,finish=1416651451763431060,duration=84096150327
[0K
[31;1mThe command "TERM=dumb gradle build connectedCheck" exited with 1.[0m
Done. Your build exited with 1.
Updated response: VM images already include fixed android-wait-for-emulator script and android SDK tools version 24.0.0 by default solving other issues.
Build Environment Updates - 2014-12-09
Brief response:
Bugged script causes your emulator don't be ready for your tests and your app is not installed due a timeout, so there are no tests performed and the build fails as a new behavior added to alert you about issues as this.
Explanation:
You are running on the background an outdated android-wait-for-emulator script that exits when the ADB server is running but your emulator is not fully booted (requires stopped state) (See point 7).
As your emulator is not ready and exists a two minutes INSTALL_TIMEOUT, your build fails with an InstallException caused by ShellCommandUnresponsiveException (See point 4).
You are trying to test an app running one command without --debug information, you could try my suggestion on comments and use gradle installDebug --debug and split the build (See point 2).
As you are using Travis CI build server, You need add logcat and connectedDevice logs to their output. I offer you one option that works but can be improved. Use your app module MOD_NAME=lib (See point 5).
You need manage concurrency, try to avoid create the AVD while you download/install gradle, etc. You can use install: true if you don't need it but I recommend you use it to install gradle (See point 3).
It's possible ignore this failure when you don't need test the app on an emulator or you still have no tests but Google added this feature to detect issues and I don't recommend that you disable it (See point 1).
You can disable run test from conflictive dependencies but is not your problem, ignore it now (See point 6).
I deleted points 8 and 9 about testing samples and sdcard usage because my response is too long but you use the sdcard on your lib and it's possible you need define another location for your sdcard, I don't know it.
Solving the emulator issue it's possible that sometimes you see the same error or other random issues as error core 137 (See point 10).
You can try to reload the job, change your configuration, use echo so server knows your build is not failing, use adb wait-for-device, check adb device state, increase ADB_INSTALL_TIMEOUT etc.
If you follow the other points, mainly to use another script and read the logs, I'm sure you'll detect and solve all the issues.
First response edited:
I didn't remember the real reason and you didn't share enough debug information but i solved this issue on my tests a weeks ago. I was not sure because I saved it as:
# com.android.ddmlib.InstallException. connectedAndroidTest run tests failed, (exceed timeout).
# #-- Issue: https://code.google.com/p/android/issues/detail?id=69735 (now optimize/reload job).
# #-- 144.6 --# Solution: https://android-review.googlesource.com/#/c/112780/ (inc. install time).
Now that i think I know the solution I add comments to my previous response:
Point 1 was a work around I used when i didn't know the reason, you don't need it now. We'll solve it.
You can add this to your build.gradle on all the tested modules to ignore this failure by now.
project.gradle.taskGraph.whenReady {
connectedAndroidTest {
ignoreFailures = true
}
}
Point 2 was another work around that is useful for split the build and avoid the problem if you don't need test.
Your real problem is about install your app on an emulator that is not ready and seems a testing issue.
Or use gradle build or gradle assembleDebug assembleDebugTest.
assemble: The task to assemble the output(s) of the project
check: The task to run all the checks.
connectedCheck: Runs checks that requires a connected device or
emulator.
build: This task does both assemble and check
Note that build does not depend on deviceCheck, or connectedCheck.
See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Android-tasks
checks requiring a connected device are launched with the anchor task
called connectedCheck.
This depends on the task androidTest and therefore will run it. This
task does the following:
Ensure the app and the test app are built (depending on assembleDebug and assembleTest)
install both apps
run the tests
uninstall both apps.
See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-tests
Point 3 was the last point adapted to Travis Yaml case. I always override install stage so I'm not sure if they currently execute gradle assemble by default using their gradle v2.0 but the best you can do is to be sure nothing is executed without you know it and use install: true.
Travis sample using ./gradlew build as the script. Or ./gradle build if you are not using gradle wrapper. Really you have gradle wrapper and use wget, i don't understand it.
install:
# Check install section: http://docs.travis-ci.com/user/build-configuration/#install
# If you'd like to skip the install stage entirely, set it to true and nothing will be run.
- true
script:
# By default Travis-ci executes './gradlew build connectedCheck' if no 'script:' section found.
- ./gradlew build
See Travis CI skip tests (Gradle Android project)
Point 4 is the issue/feature added by Google a weeks ago that helps that you know something is wrong. If you use --debug you can read the reason that no test are performed. An InstallException caused by ShellCommandUnresponsiveException.
When running connectedCheck and no tests are found, it should be
considered a failure. This will allow detecting issue where a bad setup leads to not running any existing tests. (Xavier Ducrohet)
When running connectedCheck and no tests are found, it should be
considered a failure. The absence of tests is very different than
having tests and not having them run. This feature is for the latter
case (Jake Wharton)
See issue: 76249: Gradle should break if no tests are run
See feature: 108410: Running tests with no test found will now break the build.
Point 5 was my first "bash/yaml/ruby script" trying to find the response. Really needs be improved, I only knew that is parsed as Yaml, I used Bash manual and that is used by Ruby code. I added ' ' because looks ugly on github, i omitted it here. For line is from here
I found it, and today I have found the build with after_failure logs about this: See lines 5073, 5161, 5184
You can use after_failure section to read logcat and test outputs, perhaps you find the real problem if you already have tests and the problem is another. I think an installation issue due to emulator no ready or other CI related issues. You say the app works on your personal machine.
before_script:
# - echo 'LOGCAT'
# Check logcat debug output: http://developer.android.com/tools/help/logcat.html
# Check debugging log: http://developer.android.com/tools/debugging/debugging-log.html
# Comment the lines belows to debug output and redirect it to a file. Custom tags for your app.
- adb -e logcat *:W | tee logcat.log > /dev/null 2>&1 &
after_failure:
# - echo 'FAILURE'
# Check apt configuration: http://docs.travis-ci.com/user/ci-environment/#apt-configuration
# Comment out the lines below to show log about tests with app name customized on exports section.
- sudo apt-get install -qq lynx
- export MOD_NAME=yourappmodulename
- export LOG_DIR=${TRAVIS_BUILD_DIR}/${MOD_NAME}/build/outputs/reports/androidTests/connected/
- lynx --dump ${LOG_DIR}com.android.builder.testing.ConnectedDevice.html > myConnectedDevice.log
- lynx --dump ${LOG_DIR}com.android.builder.testing.html > myTesting.log
- for file in *.log; do echo "$file"; echo "====================="; cat "$file"; done || true
Point 6 I added this only for completeness but seems useful, really i didn't try it. Ignore it now.
See linked response for: Disable run tests from conflictive dependencies
Point 7 I really pointed the main reason of your problem if I'm not wrong and i think the script can be improved as i tried to explain when i opened the issue about the emulator.
You are using a bugged android-wait-for-emulator script, so your emulator is not ready when you begin your build. They fixed it but you are using the preinstalled outdated version.
You can get the latest version using Shubham Chaudhary work around.
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- curl http://is.gd/android_wait_for_emulator > android-wait-for-emulator
- chmod u+x android-wait-for-emulator
- ./android-wait-for-emulator
- adb shell input keyevent 82 &
See: second response here or use my script version
I delete points 8 and 9 about tests and sdcard so I follow with the final response but you use the scard on your lib and we don't have permissions where is mounted by default.
Point 10
Issue 1: "ConnectedDevice > hasTests[] FAILED No tests found."
See issue: 76249: Gradle should break if no tests are run
See feature: 108410: Running tests with no test found will now break the build.
As debug logs show here and a Google search about it, Issue 1 changed to
Issue 2: Ddmlib is too agressive with timeouts in Device.java
See issue: 69735 -Ddmlib is too agressive with timeouts in Device.java
See feature:
112780 - ddmlib: Allow install timeout to be specified as an env variable
The names are very descriptive, can be useful, i thought it and waited for the feature but then i fixed my script and configuration issues and i dont need it. So issue 2 changes to:
Issue 3: "emulator is ready" message can be false.
See issue: 2932 - New android-wait-for-emulator script needs be fixed
See fix: New android-wait-for-emulator fixed
See alternative for custom it: Original public domain script fixed and comments
See recommended link for understand it: Starting and stopping android emulators
we are running ARM version on x86 architecture without gpu-on and limited resources, I don't know if is it currently possible enable it on an VM image but probably x86 emulator versions will work better. We need install KVM and I didnt try it on Travis build servers or know if it's possible but I did it on my computer, following this guide.
Emulator for android-21 needs more time to be ready and seems the important string was changed from not found to device not found. Travis team fixed it but the script redirects stderr to stdout and seems that adb server sends the misleading message running. They fixed it but you need the new version or an alternative as I do until VM images are updated.
If you do it and add logs to Travis output you'll see when your build has other issues as sdcard location or not. If you reload the job, it's possible that the emulator will be ready this time. You are running it on the background so it depends on what you are doing on your build. A litle change can do that Travis-ci kills a job if you don't manage the concurrency. Try to avoid downloads while the avd filesystem has been created. Remember that you use & so you are running it on a subshell and the resources are limited using a free plan. I didn't test other plans.
If you don't manage concurrency and resources, and design a good configuration script for your specific case, its's possible that sometimes your emulator is not ready, you see an error 137, you need a higher INSTALL_TIMEOUT and other random issues. You can try to reload the job and it's possible it works that time.
You can use adb wait-for-device to be sure emulator state is device before execute other heavy tasks, split the build, disable services and play with your resources. You can now use cache for public repositories if you disable sudo. I'm testing it here. I'm currently not using the cache but the container-based infrastructure seems works faster. All the jobs worked at the first time, less the 380.6 job. Issuing a ShellCommandUnresponsiveException as I think is your problem too, solved it reloading the job but probably I need improve my .travis.yml configuration file. So I looked for your issue, found my log and tried to improve this response.
I recommend you to use the original public domain script, fixed the string that changed and custom it for your case.
I had the same error message.
After pulling my hair out for a while I ran it against an emulator with Android 4.4.2 and it worked fine.
I was able to overcome issue by switching off my antivirus (in my particular case Kaspersky Internet Security)

How can I test my python apps using the android emulator (using Ubuntu 12.04 + kivy)?

I've managed to build two examples provided by kivy on Ubuntu 12.04 64-bit and to run those on my Nexus 4 device following basically these instructions given on the python-for-android websites using this command:
./build.py --package org.test.touchtracer --name touchtracer --version 1.0 --dir /home/bernhard/Development/kivy/examples/demo/touchtracer debug
For further development and the necessary debugging, I'd like to test my compiled python programs on the Android emulator, because copying the app to the device is a bit cumbersome & takes quite long time to transfer, I think (please correct me if you think this is not true - I have no experience yet).
So, I've created an AVD with the Android SDK Manager [19.0.2] running Android 4.4.2 on an emulated Nexus 4 device.
When I start the emulator a new window appears showing 'android' in a shiny font, but nothing else happens, seems like a frozen (emulated) device (i.e. I can't interact with the emulator). The AVD Manager lists this AVD located in my ~/.android/avd as "A valid Android Virtual Device". I've tried both Intel Atom (x86) and ARM armeabiv7a as CPU, but nothing.
Since I couldn't find good instructions on how to copy & test my python apps on the emulator, I've tried the following naively changed the debug option from above to installd
./build.py --package org.test.touchtracer --name touchtracer --version 1.0 --dir /home/bernhard/Development/kivy/examples/demo/touchtracer installd
But mostly I get this:
install:
[echo] Installing /home/bernhard/Development/python-for-android/dist/default/bin/touchtracer-1.0-debug.apk onto default emulator or device...
[exec] error: device not found
[exec] - waiting for device -
[exec] rm failed for /data/local/tmp/touchtracer-1.0-debug.apk, No such file or directory
BUILD FAILED
/home/bernhard/Development/android-sdk-linux/tools/ant/build.xml:1364: The following error occurred while executing this line:
/home/bernhard/Development/android-sdk-linux/tools/ant/build.xml:1378: exec returned: 1
Total time: 51 seconds
Traceback (most recent call last):
File "./build.py", line 412, in <module>
make_package(args)
File "./build.py", line 336, in make_package
subprocess.check_call([ANT, arg])
File "/usr/lib/python2.7/subprocess.py", line 511, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ant', 'installd']' returned non-zero exit status 1
This is confusing because the emulator is running.
Once I got something more promising, which still did not change the emulator output:
install:
[echo] Installing /home/bernhard/Development/python-for-android/dist/default/bin/touchtracer-1.0-debug.apk onto default emulator or device...
[exec] 979 KB/s (6559511 bytes in 6.542s)
[exec] WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
[exec] Error: Could not access the Package Manager. Is the system running?
installd:
BUILD SUCCESSFUL
or:
install:
[echo] Installing /home/bernhard/Development/python-for-android/dist/default/bin/touchtracer-1.0-debug.apk onto default emulator or device...
[exec] 988 KB/s (6559511 bytes in 6.482s)
[exec] WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
[exec] pkg: /data/local/tmp/touchtracer-1.0-debug.apk
[exec] - waiting for device -
[exec] rm failed for /data/local/tmp/touchtracer-1.0-debug.apk, No such file or directory
I'm sorry to be so imprecise with the different outputs, I don't understand the reasons for the differences myself. I think it can have to with the fact that the real device was connected just before one trial, or that I've deleted all touchtracer* files in my python-for-android/dist/default/bin folder.
So, finally my questions:
1) Am I using the build command correctly to install the compiled code on the emulator?
2) Why is the emulator only showing a shiny 'android' lettering without any possibility to interact?
3) Do you know any good links / tutorials on how to use an Android emulator on Ubuntu?
Many thanks in advance!
Best regards,
Bernhard
It sounds like your Android emulator is not running properly. The first run of a new AVD or is excruciatingly slow, especially on an older computer. It can literally take 10-20 minutes to get to the Android desktop if your CPU is slow.
One thing you need to make sure of is that your AVD has "Use host GPU" selected in its options. Kivy will not run on the Android emulator without that option. However it sounds to me like you never get to the point of your AVD booting completely.
I'm not clear on what your problem actually is.
Are you saying that without the emulator, your apk does build fine? I ask because the existence of the emulator shouldn't really make a difference to anything. You can test this by stopping the emulator, using the build command, and manually copying the apk to your device.
(It does look like your build sometimes completes successfully. Even if it can't copy to a device, it will be in the bin directory.)
You can upload the apk to the phone in multiple ways (even just emailing it), but the easiest way is to use the adb tool from the android sdk - plug your phone into the computer, turn on its developer mode, and run adb install /path/to/apk. This should only take a few seconds.
because copying the app to the device is a bit cumbersome & takes quite long time to transfer, I think (please correct me if you think this is not true
My above paragraph also addresses this. It's very simple and easy to install with adb, I do it all the time when developing for android. Actually, it's probably competitive with using the emulator, since both ways are ultimately typing the same command and transferring to a device (real or emulated).
I also recommend using the buildozer tool, which is a nice wrapper around the android build process with a more convenient interface. It's also capable of downloading appropriate android dependencies on its own, and interfacing with adb.

How to run Android emulator remotely

I have a android application that connects/send/receive to/from a server as part of its operation.
my final goal is to run this application on a number of android emulators on a remote machine(to save some computing resources on my laptop).
I SSHed to the remote machine and created the emulators remotely using android create avd -n AVD_xxx -t 1 .
I tried to run the emulators using emulator-arm -avd AVD_1 but it gave error that looks obvious : SDL init failure, reason is: No available video device
(if I run the command one the michine directly, it will run just fine)
I will appreciate if you help me solve this issue.
Note:
I don't need video provisions. is it possible to disable that by configuring AVD? this is just an example. you might have better solutions.
There are two options:
export $DISPLAY and show the emulator on some X display (tunneled or remotely existing)
run emulator -no-window [-no-audio] to start it without the need of a X display

Categories

Resources