The project was a C library with Java and Swift wrappers and my goal was to generate Android, iOS and Linux versions of that library using Travis. The main problem with my plan was that you have to define the "language" of project in your travis.yaml file and in my case... should it be android, objective-c or cpp project?
It would be great if travis would support multilanguage projects  or multiple yaml files per project  but apparently none of that is going to happen in the short term.
I decided to build the Linux part using docker to make sure I can use the same environment locally, in travis and in production.
Given the fact that the only way to build an iOS project is using OSX images and that there is no docker support in travis for OSX I had to use the multiple operating systems capabilities in travis .
This ended up being the most challenging part. Android projects require a lot of packages (tools, sdks, ndks, gradle...) so I decided to use docker also for this to make sure I had the same environment locally and in travis. There were some docker images for this and I took many ideas form them, but I decided to generate my own .
To not have a too crazy travis.yaml file I put all the steps to install prerequirements and to launch the build process in shell scripts (2 scripts per platform). That simplifies the travis configuration and also let me reuse the steps if I want to build locally or in jenkins eventually. My project folder looks like this:
The most interesting scripts (if any) are the android and ios ones.
echo "no additional requirements needed"
xcodebuild build -workspace ./project.xcworkspace -scheme 'MyLibrary' -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.3'
docker pull ggarber/android-dev
docker run --rm -it --volume=$(pwd):/opt/workspace --workdir=/opt/workspace/samples/android ggarber/android-dev gradle build
With that structure and those scripts the resulting travis.yaml file is very simple:
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then ./scripts/linux/before_install.sh ; fi
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then ./scripts/android/before_install.sh ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./scripts/ios/before_install.sh ; fi
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then ./scripts/linux/script.sh ; fi
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then ./scripts/android/script.sh ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./scripts/ios/script.sh ; fi
This is working fine although the build process is a little bit slow so these are some ideas to explore to try to improve it in the future:
- Linux and Android builds could run in parallel.
- Android docker images are very big (not only mine but all the ones I found). According to docker hub it is 2GB compressed image. Probably there are ways to strip this down.
- I'm not caching the android packages being downloaded during the build process inside the docker container.