Fastlane and Travis CI Integration for Android

Pratik Gawand
3 min readMar 15, 2018

--

As Buddybuild is now a part Apple it has stopped support for Android and no longer ships Android APK to Play Store. Buddybuild gave all the one month to move to Android Project to a different CI/CD provider.

Searching for a new CI/CD came across fastlane https://fastlane.tools

Let just get started with my take on Fastlane with Travis CI

Let Setup Fastlane Locally first

  1. Make sure you got Ruby installed
  2. Install fastlane on your machine. $ gem install fastlane -NV
  3. Goto your Android Project and hit fastlane init.
  4. Now you would see the a fastlane directory with two files
  5. AppFile for you application meta data and Fastfile for defining your lane i.e fastlane.
  6. Now goto the Google Play Console and create a role for fastlane follow the link below for details →Creating Fastlane Role.
  7. Download the json file which you will recieve after creating a fastlane role.
  8. Setup the Environment varibale for Fastlane

export LC_ALL=en_US.UTF-8

export LANG=en_US.UTF-8

9. Add it in your root Project and in the Appfile. Example renamed the json file to fastlane.json and add your application package name.

10. Now add lane in Fastfile, Creates a deployment to alpha assuming you have the keystore.jks file in the project root directory. Place the Keystore Password, Alias and Alias Password in the file. (Note: Deploying from local machine)

10. Now hit the run fastlane deploy_production in the terminal. (Note: deploy_production is the method name)

11. And after few minutes your app to alpha store Note: In the supply method passed “aplha” i.e. It will deploy to Alpha Store. If you want you can directly deploy to Beta or Production Store directly just by changing the parameter check the link for more details https://docs.fastlane.tools/actions/supply.

This is one of the approach you can do Fastlane Deployment from you Local machine.

Now Integrating Fastlane with Travis

Now that we have we have configured fastlane in our project, let go to travis

  1. I hope you have configured Travis on your Android Repository.
  2. I am going to modify the lane deploy_production which we wrote a bit. Here I am trying to pass the Keystore Password, Alias and Alias Password as parameter as keeping in mind security aspect.

3. Here now our deployment command will change to fastlane after setting up the three environment variable, as we can easily and securely set the variable in Travis CI.

  • KEYSTORE_ALIAS
  • KEYSTORE_ALIAS_PASSWORD
  • KEYSTORE_PASSWORD
$ fastlane deploy_production KEYSTORE_PASSWORD:KEYSTORE_PASSWORD KEYSTORE_ALIAS:KEYSTORE_ALIAS KEYSTORE_ALIAS_PASSWORD:KEYSTORE_ALIAS_PASSWORD

I have also added the Slack notification you will need to create and add your Slack Webhook Token.

4. Now jumping to .travis.yml file. We will also require the keystore.jks file for generating the signed apk. As we currently can pass the files to Travis Build, I have stored the keystore.jks file on a AWS S3 bucket. For that we will need to create environment variable for AWS access key and secret access key.

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

(Note: You create a user to generate these key from AWS IAM Service also provide the user with S3 Permission)

configure_aws.sh
.travis.yml

In the .travis.yml file we run few Unit Test and we login to AWS and download the keystore.jks file which we will need to generate the signed APK.

That its we have integrated Fastlane with Travis. A very big thumbs up to the Fastlane team for such a awesome tools. Hope you liked the article.It is a way of integrating there might a a diffrent approach to it Feel free for any question ,feedback or suggestion good or bad. Thanks Cheers.

🚀🚀🚀=====≥=== Enjoy your fastlane====>🚀🚀🚀

--

--