As of writing this post Travis CI now has beta support to Android , and can be used to build android APK file and publish it to GitHub releases.

Travis CI

Travis CI is a hosted continuous integration platform which can be used to run tests and build apps when code is pushed to GitHub. Travis works only with GitHub. It is free for open-source projects but you can also choose a suitable plan for private projects.

What is in it for meteor

Meteor is a popular platform for building real time web applications and is quite capable platform to create amazing mobile applications for both iOS and Android. Building a meteor based android app is a repetitive task that can be automated. You can build the app and publish a signed APK of it directly to GitHub releases just by pushing your code to GitHub. For now we will concentrate only on Android app build automation on Travis CI.

Setup

You can learn how to add your project to Travis here. create a .travis.yml file and add the following data to .travis.yml

sudo: required

language: android

android:

components:

- platform-tools

- tools

- build-tools-22.0.1

- android-22

node_js:

# since meteor is now ver1.4 and uses node-v4.4.7

- 4.4.7

before_install:

- npm install -g spacejam

- npm install -g cordova

- curl https://install.meteor.com/ | sh

services:

- mongodb

script: spacejam test --driver-package practicalmeteor:mocha

We used android as language to utilize the android utilities of Travis. Node.js is available on any language or platform The above Travis config installs meteor and runs meteor tests, feel free to use any other test packages spacejam is just a cli-test reporter, learn more about meteor testing here. You can also change the android SDK and build-tools versions. So far so good, now we will take care of automating Travis to build a signed APK.

3. To build a signed APK we must first build meteor and create an unsigned APK, and then sign it using jar-signer. On your local machine run the snippet below (when prompted for password enter a strong password and make sure to backup the .keystore file, future releases require the same key to be used again).

keytool -genkey -alias your-app-name -keyalg RSA -keysize 2048 -validity 10000

this will create a .keystore file(in home directory if it doesn’t exist) and adds a entry for your app, use your app name for alias.

4. Copy the .keystore file (from home directory) to your project folder. You can’t use this file directly on GitHub or Travis since it contains sensitive information. Encrypt the file using Travis command line utility. Install it by running.

#requires ruby installation

gem install travis

Next you can encrypt the .keystore file using

travis encrypt-file .keystore --add

You will see a .keystore.enc file in your project directory and you must see an entry in .travis.yml now something like this

before_install:

- openssl aes-256-cbc -K $encrypted_058af3642dc1_key -iv $encrypted_058af3642dc1_iv

-in .keystore.enc -out .keystore -d

You can safely delete the .keystore file from project folder. Now we must find a way to communicate our store and key passwords to jar-signer. We can use Travis command line utility again to create a encrypted hash and add them to environment variables.

travis encrypt storepass=YOUR_STORE_PASSWORD --add env.global

travis encrypt keypass=YOUR_KEY_PASSWORD --add env.global

You must see an entry on .travis.yml now something like this

env:

global:

- secure: < a long string >

- secure: < a long string >

Since we have everything required, all we have to do is create an unsigned apk using meteor build command and then sign it. Add the following to the .travis.yml, be sure to replace server URL in meteor build and also your-apk-name to the app name but leave release-unsigned.apk as it is.

before_deploy:

- meteor build $HOME --server <server-url>

- cp $TRAVIS_BUILD_DIR/.keystore $HOME

- jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 $HOME/android/release-unsigned.apk your-apk-name -keystore $HOME/.keystore -storepass $storepass -keypass $keypass

- "${ANDROID_HOME}/build-tools/22.0.1/zipalign 4 $HOME/android/release-unsigned.apk $HOME/android/your-apk-name.apk"

Perfect, now we have a signed apk now we can deploy the build to GitHub releases.

Deploy to GitHub releases

Generate an API-Key here and enable scopes for repo, repo:status, repo_deployment and public_repo.

Access scope for API-KEY

Now add the following to .travis.yml

deploy:

provider: releases

api_key: <your api key for github>

# replace your-apk-name

file: "$HOME/android/your-apk-name.apk"

skip_cleanup: true

on:

tags: true

Your .travis.yml file must now look like this

sample .travis.yml file

Make sure you delete the .keystore file from your project and push your project to GitHub, deploy works only on tags so make sure you tag your commit. After a successful build you can find your app’s APK on your GitHub repo releases.

That’s it, hope you found this post useful.

Android support in Travis is under beta as of now so there may be changes in implementation in future so please make sure you check here https://docs.travis-ci.com/user/languages/android