Skip to content

Instantly share code, notes, and snippets.

@luongvo
Forked from mugifly/circle.yml
Created January 3, 2018 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luongvo/fec4e674882d91c27784ed7bdc4a4a22 to your computer and use it in GitHub Desktop.
Save luongvo/fec4e674882d91c27784ed7bdc4a4a22 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment