Skip to content

Instantly share code, notes, and snippets.

@mugifly

mugifly/circle.yml

Last active Jun 29, 2018
Embed
What would you like to do?
Faster test & Build of Android Studio Project (Gradle Project) on Circle-CI.
machine:
java:
version: oraclejdk8
environment:
# Java options
JAVA_OPTS: "-Xms512m -Xmx2048m"
# ADB options
ADB_INSTALL_TIMEOUT: 5000
dependencies:
pre:
# Install the android packages
- echo y | android update sdk --no-ui --all --filter "extra-google-market_licensing,extra-google-play_billing"
# [HINT] Almost packages are pre installed: https://circleci.com/docs/build-image-precise/#android
post:
# Create the android emulator
- echo n | android create avd -n test_android_17 -f -t android-17
# [HINT] Circle-CI already have built-in emulator (circleci-android22), but it's so heavy.
# Make a SD Card image file for the android emulator
- mksdcard -l e 128M sdcard.img
test:
pre:
# Start the android emulator
- emulator -avd test_android_17 -no-audio -no-boot-anim -no-window -sdcard sdcard.img:
background: true
parallel: true
# Start the adb server
- fb-adb start-server:
background: true
override:
# Generate a debug-apk
- ./gradlew assembleDebug -PdisablePreDex
# [Hint] About -PdisablePreDex, please see http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance.
# Wait for emulator to boot
- circle-android wait-for-boot; sleep 5
# Pre-install the app (debug-apk)
- fb-adb install app/build/outputs/apk/app-debug.apk
# Allow the SET_ANIMATION_SCALE permission to the app
- fb-adb shell pm grant "${APP_PACKAGE_NAME}" android.permission.SET_ANIMATION_SCALE
# Unlock the emulator screen
- fb-adb shell input keyevent 82
# Install the app (test-apk) and Run the tests
- ./gradlew connectedDebugAndroidTest -PdisablePreDex --stacktrace
# Save a screenshot to Circle-CI Artifacts
- fb-adb rcmd screencap -p > $CIRCLE_ARTIFACTS/screen-$(date +"%T").png
# Copy the generated apk files to Circle-CI Artifacts
- cp -r app/build/outputs/apk/ $CIRCLE_ARTIFACTS
# Copy the test results to Circle-CI Artifacts
- cp -r app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
# [HINT] The following example will upload the generated apk file to Slack and Google Drive
#deployment:
# staging:
# branch: /.*/ # all branch
# commands:
# - |
# # Make a filename of APK
# export apk_name="build-${CIRCLE_BRANCH}-`git rev-parse --short HEAD`.apk"
# # Upload the APK file to Slack
# curl https://slack.com/api/files.upload -F token="${SLACK_TOKEN}" -F channels="${SLACK_CHANNEL}" -F title="${apk_name}" -F filename="${apk_name}" -F file=@app/build/outputs/apk/app-debug.apk
# # Upload the APK file to Google Drive
# # [HINT] You can get the refresh token of Google using gdrive command: https://github.com/prasmussen/gdrive
# curl -L -o gdrive "https://docs.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA&export=download"; chmod u+x gdrive
# ./gdrive --refresh-token "${GDRIVE_REFRESH_TOKEN}" upload --parent "${GDRIVE_DIR_ID}" --name "${apk_name}" app/build/outputs/apk/app-debug.apk
@mugifly

This comment has been minimized.

Copy link
Owner Author

@mugifly mugifly commented Jul 3, 2016

Circle-CI already have a built-in emulator (circleci-android22).
But it seem to little heavy. Actually, it brought following problems.

  • Test failures - "Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds."
  • Execution of and "circle-android wait-for-boot" and "adb install" command was too slowly. It takes 2 - 10 minutes .

To improvement the above problems, we tried the more lower version of emulator.
We can choose the any version of emulator. Additionaly, the system images of some versions has already prepared on Circle-CI.

- echo n | android create avd -n test_android_17 -f -t android-17

It brought more faster execution of the tests!!
Actually, a time of all execution was shrunk to 7 minutes from around 20 minutes :)

@jachenry

This comment has been minimized.

Copy link

@jachenry jachenry commented Sep 19, 2016

@mugifly what is the point of assembling and installing when connectedDebugAndroidTest does the same thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.