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:
# Fix the CircleCI path
function getAndroidSDK(){
export PATH=“$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH”
DEPS=“$ANDROID_HOME/installed-dependencies”
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
fi
}
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”
done
)
}
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.
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 (https://circleci.com/docs/android). 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:
test:
override:
# 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: