Setting up Travis CI - noojman/Test-Prep-Grading-App GitHub Wiki

The standard instructions were followed as far as setting up GitHub to work with Travis CI. That included syncing the Travis account with the Github account and enabling this project for continuous integration.

The configuration file, .travis.yml, took some special considerations for full functionality.

First, we set the language, jdk, cache, and sudo settings.

 language: android
 jdk: oraclejdk8
 cache:
   directories:
     - node_modules
 sudo: false

Then, we set the android components.

 android:
   components:
     - tools # to get the new `repository-11.xml`
     - tools # to install Android SDK tools 28.0.3
     - platform-tools
     - build-tools-28.0.3
     - android-28
     - android-22

     - sys-img-armeabi-v7a-android-22

sys-img is required for testing, as an emulator is run during the CI. Both android-28 and android-22 are required; version 28 for compiling the project, and version 22 for running the emulator.

To successfully compile the Android project in CI, we have to provide the proper permissions in before_install.

 before_install:
   - chmod +x gradlew
   - yes | sdkmanager "platforms;android-28"

We will now set a timer on the emulator environment as an exit strategy for an installation timing out.

 env:
   global:
     # install timeout in minutes (2 minutes by default)
     - ADB_INSTALL_TIMEOUT=8

Next, we will set our emulator settings in before_script.

 before_script:
   - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
   - emulator -avd test -no-skin -no-audio -no-window &
   - android-wait-for-emulator
   - adb shell input keyevent 82 &

This emulator uses android-22. There are some compatibility issues around different emulator versions and settings, and this one worked perfectly for this application.

Finally, we determine our script for compiling and running our tests.

 script:
   - android list target
   - ./gradlew connectedAndroidTest

Now, Travis CI should be able to compile and run tests automatically on each push to master on GitHub.