Skip to content

Instantly share code, notes, and snippets.

@kumy
Created August 19, 2017 16: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 kumy/09f529b196153d91eb0c8141dfa2f0c7 to your computer and use it in GitHub Desktop.
Save kumy/09f529b196153d91eb0c8141dfa2f0c7 to your computer and use it in GitHub Desktop.
export PATH=${PATH}:/opt/android-sdk-linux/emulator/:/opt/android-sdk-linux/tools/bin/
apt-get update && apt-get install -y expect openjdk-8-jdk git wget libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5 lib32z1 unzip && apt-get clean
mkdir -p /opt/android-sdk-linux && cd /opt/android-sdk-linux && wget --output-document=android-sdk.zip --quiet https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip && unzip android-sdk.zip && rm -f android-sdk.zip
yes | /opt/android-sdk-linux/tools/bin/sdkmanager --licenses
sdkmanager \
"tools" \
"emulator" \
"add-ons;addon-google_apis-google-24" \
"extras;google;m2repository" \
"extras;android;m2repository" \
"build-tools;26.0.1" \
"platforms;android-26" \
"system-images;android-23;google_apis;x86_64" \
"extras;google;google_play_services" \
--verbose
avdmanager create avd -n emulator --package "system-images;android-23;google_apis;x86_64" -c 50M -d "Nexus 4" -g google_apis
cat <<'EOF' > $HOME/restart-emulator.sh
#! /bin/bash
#
export SHELL=/bin/bash
export PATH=/opt/tools:/opt/android-sdk-linux/emulator/:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools:$PATH
export TERM=dumb
export QEMU_AUDIO_DRV=none
cd "$HOME"
PIDFILE=emulator.pid
if [ -f $PIDFILE ]; then
OLDPID=$(cat $PIDFILE)
if [ -d /proc/$OLDPID ]; then
kill $OLDPID
count=0
while ((count < 10 )); do
if [ -d /proc/$OLDPID ]; then
((count++))
sleep 1
else
count=10
fi
done
kill -9 $OLDPID 2> /dev/null
fi
fi
if [ "x$1" = "x--stop" ]; then
rm -f $PIDFILE
else
emulator -avd emulator -no-window -no-boot-anim -memory 2048 -engine classic -qemu -enable-kvm &
echo $! > $PIDFILE
fi
EOF
chmod +x $HOME/restart-emulator.sh
cat <<'EOF' > /usr/local/bin/build-cgeo.sh
# restart the emulator if possible so that it gets ready to test the build
[ -x "$HOME"/restart-emulator.sh ] && "$HOME"/restart-emulator.sh
# accept Android licenses. these are the MD5 hashes of the license texts, so they may need to be adapted on license changes
[ ! -d "/opt/android-sdk-linux/licenses" ] && mkdir "/opt/android-sdk-linux/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "/opt/android-sdk-linux/licenses/android-sdk-license"
# gradle needs the sdk.dir in local.properties. Not sure if a template exists on the server, therefore we create it on demand.
echo "sdk.dir=/opt/android-sdk-linux" > local.properties
# get all the necessary keys
cp /srv/private.properties .
# set the emulator preferences
cp /srv/cgeo.geocaching_preferences.xml main/cgeo.geocaching_preferences.xml
# build everything
# re-added the clean target, since builds fail after upgrading the unmock or java plugin of gradle
# add --stacktrace temporarily for finding the root of deprecated tasks
# kumy: removed createBasicDebugCoverageReport
./gradlew --scan clean testDebug checkstyle lintBasicDebug -Pandroid.testInstrumentationRunnerArguments.notAnnotation=cgeo.geocaching.test.NotForIntegrationTests --stacktrace
#./gradlew --no-daemon --stacktrace clean testDebug checkstyle lintBasicDebug -Pandroid.testInstrumentationRunnerArguments.notAnnotation=cgeo.geocaching.test.NotForIntegrationTests --scan
#./gradlew --no-daemon --stacktrace clean testDebug checkstyle lintBasicDebug -Pandroid.testInstrumentationRunnerArguments.notAnnotation=cgeo.geocaching.test.NotForIntegrationTests --scan
# shutdown emulator
[ -x "$HOME"/restart-emulator.sh ] && "$HOME"/restart-emulator.sh --stop
# cleanup
[ -f private.properties ] && rm private.properties
[ -f main/cgeo.geocaching_preferences.xml ] && rm main/cgeo.geocaching_preferences.xml
[ -f main/res/values/keys.xml ] && rm main/res/values/keys.xml
EOF
chmod +x /usr/local/bin//build-cgeo.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment