Android Challenges and circle.yml file



I am finding it challenging to set Android up on CircleCI. There doesn’t seem to be a well documented way to set up the circle.yml file specifically for Android that allows me to step through and add the functionality I need to address. Most examples out there fail in one way or another. My circle.yml looks like this:

ANDROID_HOME: /home/ubuntu/android
version: oraclejdk8

- ~/.android
- ~/android
- (echo “Downloading Android SDK v19 now!”)
- source scripts/ && getAndroidSDK

- $ANDROID_HOME/tools/emulator -avd testAVD -no-skin -no-audio -no-window
- ./gradlew clean assembleDebug
- ./gradlew assembleDebugTest
- source scripts/ && waitForAVD
- (echo “Running JUnit tests!”)
- ./gradlew connectedAndroidTest

This is the file referenced:


# Fix the CircleCI path
function getAndroidSDK(){
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"


if [ ! -e $DEPS ]; then
cp -r /usr/local/android-sdk-linux $ANDROID_HOME &&
echo y | android update sdk -u -a -t android-19 &&
echo y | android update sdk -u -a -t platform-tools &&
echo y | android update sdk -u -a -t build-tools-21.1.2 &&
echo y | android update sdk -u -a -t sys-img-x86-android-19 &&
#echo y | android update sdk -u -a -t addon-google_apis-google-18 &&
echo no | android create avd -n testAVD -f -t android-19 --abi default/x86 &&
touch $DEPS

function waitForAVD {
local bootanim=""
export PATH=(dirname (dirname $(which android)))/platform-tools:$PATH
until [[ "bootanim" =~ "stopped" ]]; do sleep 5 bootanim=(adb -e shell getprop init.svc.bootanim 2>&1)
echo "emulator status=$bootanim"

These are the errors I get:

Line: $ $ANDROID_HOME/tools/emulator -avd testAVD -no-skin -no-audio -no-window
Error message:
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Ple ase ensure KVM is properly installed and usable.

CPU acceleration status: KVM is not installed on this machine (/dev/kvm is missing). $ANDROID_HOME/tools/emulator -avd testAVD -no-skin -no-audio -no-window returned exit code 1

Line: $ ./gradlew clean assembleDebug
Error message:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain ./gradlew clean assembleDebug returned exit code 1

Line: $ ./gradlew assembleDebugTest
Error message:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain ./gradlew assembleDebugTest returned exit code 1

There is a gradlew file in the root directory of the app on github.

Android: Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

They have specified in the docs that "One important note: it’s not possible to emulate Android on x86 or x86_64 on our build containers. The Android emulator requires KVM on Linux, and we can’t provide it. So you might want to create the avd with --abi default/armeabi-v7a



Thanks for that note PrabhatPandey. I dug into that documentation you referred to ( I change the emulator configuration, doing away with the separate script altogether. I’m also trying a different dependency script. So now my circle.yml file looks like this, but now failing at the gradle dependencies:

ANDROID_HOME: /home/ubuntu/android
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
version: oraclejdk8

- echo y | android update sdk --no-ui --all --filter “platform-tools”
- echo y | android update sdk --no-ui --all --filter “android-23”
- echo y | android update sdk --no-ui --all --filter “build-tools-23.0.2”

# start the emulator
- emulator -avd circleci-android22 -no-audio -no-window:
background: true
# wait for it to have booted
- circle-android wait-for-boot
# unlock the emulator screen
- sleep 30
# run build
- ./gradlew assembleDebug
# run tests against the emulator.
- ./gradlew connectedAndroidTest -PdisablePreDex
# copy the build outputs to artifacts
- cp -r app/build/outputs $CIRCLE_ARTIFACTS
# copy the test results to the test results directory.
- cp -r app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS

I get the error under dependencies:

gradle dependencies
export TERM="dumb"
if [ -e ./gradlew ]; then ./gradlew dependencies;else gradle dependencies;fi
returned exit code 1
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain Action failed: gradle dependencies

According to the documentation, they load ./gradlew dependencies automatically if there is a Gradle wrapper checked in to the root of the repository. It seems like something is going wrong when this happens. Maybe I shouldn’t include gradlew in the build root (could gitignore it)? Or maybe it has a problem with one or more of the dependencies? Or maybe I need to add an additional line to the circle.yml dependencies? Can’t find CircleCI documentation on this, so basically just playing the guessing game and coming up short. Here is the gradle dependencies for reference:

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
testCompile 'junit:junit:4.12’
compile '’
compile '’
compile ‘’

Any ideas what needs to be done?


@kbourne This SO questions looks like the exactly the same issue as yours.

Do you checkin your gradle wrapper scripts to Github?


@kimh Should I checkin all the /gradle/wrapper/ directory into git or only /gradle/wrapper/gradle-wrapper.propoerties ?


Ok I got my anwser from gradle web site Gradle wrapper