# How to Deploy APK to GitHub releases with Travis CI

Travis is a useful service for building and testing your code. Once you are familiar with Travis, you will likely start building with Travis because it is very easy to start with. Usually, when building Android Project, you want a resulting APK to ship. As Travis builds your APK, you are able to extract that APK through Gradle script and publish it somewhere (even GitHub). But you can do exactly the same with just a few lines in .travis.yml.

3 steps to start publishing APK to GitHub releases through Travis:

### Step #1

Configure your repository on GitHub and make sure that .travis.yml is present in the root of your repository. Here’s sample .travis.yml file:

### Step #2

Download the Travis CI command line client and run travis setup releases in the root directory of your repository.

2. When asked for file to upload insert yourapp/build/outputs/apk/yourapp*release*.apk.
3. Deploy only from username/Repo? Type yes.
4. Encrypt API key? Yes! This is an important part of keeping access to your repo private.

Now you will be able to see that travis added several lines of script in your travis.yml file. They are as follows:

Everything is almost OK by now but there are several nuances.

1. At this time Travis will treat yourapp*release*.apk like yourapp*release*.apk and not like yourapp...something...release...something.apk. So there is a parameter in Travis called file_glob which should be enabled if you want files to be interpreted as globs (* and ** wildcards).
2. You should supply skip_cleanup: "true" because otherwise Travis may clean all APKs.
3. (optional) You may want to specify the branch on which Travis is supposed to build APKs. This should be inserted in the on: section like:

The resulting deploy section:

### Step #3

In order to successfully push your APK to GitHub, you need to put a tag on the commit that has just been built. To do that, we will add a new section called after_success: where we will execute custom script which sets current build tag. The script set_tags.sh is as follows:

Place this script in the root directory of your project. And then add this 2 lines to .travis.yml:

By now you should be able to build and publish your APKs to GitHub releases sections. It will look like this:

Now you can publish your APKs to GitHub releases with no hassle! A sample project can be found here.

Happy publishing!