Engineering

13 May, 2019

How to publish your Android app to an S3 bucket using Gradle

If you ever need to publish your Android app in a simple way outside the Play Store, publishing the app .apk file to an S3 bucket could be a good solution.

António Valente

Software Engineer

How to Publish your Android app to an S3 bucket using Gradle - Coletiv Blog

If you ever need to publish your Android app in a simple way outside the Play Store, publishing the app .apk file to an S3 bucket could be a good solution. Then you’ll just need to share the generated link to that .apk file.

Here’s how to do it.

1. Create an AWS S3 bucket

If you don’t have one already, refer to the AWS documentation for this step.

2. Create an IAM user

Again, refer to the AWS documentation to check how to do this. Just make sure that you select Programmatic access as the type of access for this user and save the Access Key and Secret Key.

3. Setup your S3 variables

You can either set up the S3 variables in the project build script or per individual module if you prefer. In this example, I will do it in the project. Just open the build.gradle file and add the following code.

allprojects { project.ext.AWS_S3_BUCKET = "YOUR BUCKET NAME" project.ext.AWS_S3_KEY_ID = "YOUR BUCKED SECRET ID" project.ext.AWS_S3_KEY_SECRET = "YOUR BUCKED SECRET KEY" project.ext.AWS_S3_APK_TARGET_FOLDER = "YOUR S3 TARGET FOLDER" }

For security reasons, I highly recommend that you save the Access Key and Secret Key as environment variables so they won’t end up in your code repository.

4. Add the publish task to your project

First, you need to download the code for the publish task, find it in this gist, and put it in your app folder.

Then, in the build.gradle of each application you want to publish, add the following:

apply from: 'publishApkToS3.gradle'

Keep in mind that this task uses CURL, so make sure you have it installed in your machine.

5. Publish your app to S3

Finally, you just need to execute the following command to publish your app to the S3 bucket.

publish{flavor-name}ToS3

If you’re planning on running this on your CI, add the following commands to your configuration file.

chmod +x ./gradlew ./gradlew publish{flavor-name}ToS3

Android

Software Development

Gradle

S3 Bucket

Join our newsletter

Be part of our community and stay up to date with the latest blog posts.

Subscribe

Join our newsletter

Be part of our community and stay up to date with the latest blog posts.

Subscribe

You might also like...

Go back to blogNext
How to support a list of uploads as input with Absinthe GraphQL

Engineering

26 July, 2022

How to support a list of uploads as input with Absinthe GraphQL

As you might guess, in our day-to-day, we write GraphQL queries and mutations for Phoenix applications using Absinthe to be able to create, read, update and delete records.

Nuno Marinho

Software Engineer

Flutter Navigator 2.0 Made Easy with Auto Router - Coletiv Blog

Engineering

04 January, 2022

Flutter Navigator 2.0 Made Easy with Auto Router

If you are a Flutter developer you might have heard about or even tried the “new” way of navigating with Navigator 2.0, which might be one of the most controversial APIs I have seen.

António Valente

Software Engineer

Enabling PostgreSQL cron jobs on AWS RDS - Coletiv Blog

Engineering

04 November, 2021

Enabling PostgreSQL cron jobs on AWS RDS

A database cron job is a process for scheduling a procedure or command on your database to automate repetitive tasks. By default, cron jobs are disabled on PostgreSQL instances. Here is how you can enable them on Amazon Web Services (AWS) RDS console.

Nuno Marinho

Software Engineer

Go back to blogNext