Gitlab - Local Gitlab Runner for Android (setup your computer with real usb attached devices)
#!/usr/bin/env bash
#
# Install required dependencies
# sdkmanager can be found in $ANDROID_HOME/tools/bin/sdkmanager
#
for I in "platforms;android-25" \
"platforms;android-23" \
"platforms;android-21" \
"build-tools;25.0.3" \
"build-tools;25.0.2" \
"extras;google;m2repository" \
"extras;android;m2repository" \
"extras;google;google_play_services"; do
echo "Trying to update with tools/bin/sdkmanager: " $I
echo y | sdkmanager $I
done
sdkmanager --update
#!/usr/bin/env bash
#
# Copy env variables to app module gradle properties file
#
PROPERTIES_FILE_PATH=gradle.properties
set +x // dont print the next lines on run script
printenv | tr ' ' '\n' > $PROPERTIES_FILE_PATH
set -x
#!/usr/bin/env bash
#
# Run any adb command on all the connected devices to avoid:
# "error: more than one device and emulator"
#
adb devices | while read line
do
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ]
then
device=`echo $line | awk '{print $1}'`
echo "$device $@ ..."
adb -s $device $@
fi
done
stages:
- build
- test
cache:
key: ${CI_PROJECT_ID}
paths:
- .gradle/
before_script:
- sh scripts/cp-env-to-properties.sh
- sh scripts/adb-all.sh uninstall com.your.app.package # to avoid INSTALL_FAILED_UPDATE_INCOMPATIBLE
build:
type: build
script:
- sh scripts/install-android-dependencies.sh
- ./gradlew assemble --stacktrace
unit_tests:
type: test
script:
- ./gradlew test --stacktrace
artifacts:
paths:
- app/build/outputs/
ui_tests:
type: test
script:
# Wake up screen
- sh scripts/adb-all.sh shell input keyevent 26 # KEYCODE_POWER
- sh scripts/adb-all.sh shell input keyevent 3 # HOME
# run your UI tests tasks, in my case I use spoon everywhere
- ./gradlew spoonDebugAndroidTest --stacktrace || true # allow to get artficat on failure
artifacts:
paths:
- app/build/outputs/
- app/build/spoon/