Skip to content

Commit 577b655

Browse files
authored
add android setup recipe for new build environments
1 parent 21dfcd2 commit 577b655

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

user/languages/android.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Android builds are not available on the macOS environment.
1616

1717
### Overview
1818

19+
> Android builds are officially supported only on our Trusty Build environment at this time hence you'll need to explicitly specify `dist: trusty` in your .travis.yml file.
20+
1921
Travis CI environment provides a large set of build tools for JVM languages with [multiple JDKs, Ant, Gradle, Maven](/user/languages/java/#overview), [sbt](/user/languages/scala#projects-using-sbt) and [Leiningen](/user/languages/clojure).
2022

2123
By setting
@@ -28,8 +30,6 @@ dist: trusty
2830
2931
in your `.travis.yml` file, your project will be built in the Android environment which provides [Android SDK Tools](http://developer.android.com/tools/sdk/tools-notes.html) 25.2.3.
3032

31-
> Android builds are only supported on our Trusty image at this time hence you'll need to explicitly specify `dist: trusty` in your .travis.yml file.
32-
3333
Here is an example `.travis.yml` for an Android project:
3434

3535
```yaml
@@ -200,6 +200,52 @@ As for any JVM language, it is also possible to [test against multiple JDKs](/us
200200

201201
For Android projects, `env` and `jdk` can be given as arrays to construct a build matrix.
202202

203+
## Building Android projects on new build environments
204+
205+
The `dist: trusty` build environment is the only supported build environment for Android but if you would like to build on newer build environments e.g. `dist: jammy`, you can exercise your access to the Travis CI build environments and install required packages and tools. An example .travis.yml config can be reviewed below:
206+
207+
```yaml
208+
os: linux
209+
language: java
210+
jdk: openjdk17
211+
212+
env:
213+
global:
214+
- ANDROID_HOME=$HOME/travis-tools/android
215+
- ANDROID_SDK_ROOT=$HOME/travis-tools/android
216+
217+
before_install:
218+
# PREPARE FOR ANDROID SDK SETUP
219+
- mkdir -p $HOME/travis-tools/android && mkdir $HOME/.android && touch $HOME/.android/repositories.cfg
220+
- cd $ANDROID_HOME && wget -q "https://dl.google.com/android/repository/commandlinetools-linux-10406996_latest.zip" -O commandlinetools.zip
221+
- unzip -q commandlinetools.zip && cd cmdline-tools
222+
- mv * tools | mkdir tools && cd $TRAVIS_BUILD_DIR
223+
224+
# SETUP PATH(s)
225+
- export PATH=$ANDROID_HOME/cmdline-tools/tools/bin/:$PATH
226+
- export PATH=$ANDROID_HOME/emulator/:$PATH
227+
- export PATH=$ANDROID_HOME/platform-tools/:$PATH
228+
229+
install:
230+
# INSTALL REQUIRED ANDROID SDK TOOLS
231+
- sdkmanager --sdk_root=$ANDROID_HOME --list | awk '/Installed/{flag=1; next} /Available/{flag=0} flag'
232+
- yes | sdkmanager --sdk_root=$ANDROID_HOME --install "platform-tools" "platforms;android-33" "build-tools;33.0.2" "emulator" "system-images;android-33;google_apis;x86_64"
233+
- sdkmanager --list --sdk_root=$ANDROID_HOME | awk '/Installed/{flag=1; next} /Available/{flag=0} flag'
234+
# CREATE AVD
235+
- echo "no" | avdmanager --verbose create avd --force --name "my_android_33" --package "system-images;android-33;google_apis;x86_64" --tag "google_apis" --abi "x86_64"
236+
- sudo chmod -R 777 /dev/kvm
237+
# Start emulator in background and wait for it to start
238+
- adb kill-server && adb start-server &
239+
- sleep 15 # sleep values may require adjusting depending on the specific build environment
240+
- emulator @my_android_33 -no-audio -no-window &
241+
- sleep 60
242+
243+
script:
244+
- sdkmanager --list --sdk_root=$ANDROID_HOME | awk '/Installed/{flag=1; next} /Available/{flag=0} flag'
245+
- adb devices
246+
- .....
247+
```
248+
203249
## Examples
204250

205251
- [roboguice/roboguice](https://github.com/roboguice/roboguice/blob/master/.travis.yml) (Google Guide on Android)

0 commit comments

Comments
 (0)