Build & Upload Android App to Google Drive Using Fastlane

Paulo Carvalho
4 min readOct 8, 2023

--

Developing an app for an account for which you don’t have programatic access and find yourself constantly having to manually build and upload? This may be a simple alternative.

Introduction

In most cases, you should be able to create an end to end CICD using Fastlane and Github Actions to deploy apps to the Play Store as shown below:

However, what happens if you are developing for a client that is unable to provide you with an account API key for app uploads?

We will go over a simple alternative where you can still automate most of the build process and have the build artifacts uploaded to a Google Drive where you can then do a single manual step of uploading the final build files into the Play Console.

This is a particularly useful time saver when you need to build multiple environments (staging, production, etc).

Configure Fastlane

We will configure Fastlane in exactly the same way as shown in this article but without the API Key for Google Play account access. In the end, you will have a Fastfile that looks like the one below:

default_platform(:android)
platform :android do
desc "Deploy a new version to the Google Play - Alpha"
lane :deploy_alpha do
gradle(task: "clean bundleRelease -PMYAPP_UPLOAD_STORE_PASSWORD=#{ENV['STORE_PASSWORD']} -PMYAPP_UPLOAD_KEY_PASSWORD=#{ENV['KEY_PASSWORD']}")
upload_to_play_store(track: 'alpha')
end
end

However, the upload_to_play_store command will not work. This is where Google Drive comes in.

Configure Google Drive + Fastlane Integration

In order to connect Fastlane to Google Drive we will be using the Fastlane plugin google_drive.

Step 1: Install Plugin

To install it, run fastlane add_plugin google_drive from inside your Android’s repository.

Step 2: Service Account

In order for Fastlane to be able to access your Google Drive folder, you will need to go into your Google Cloud account and create a service account.

You do not need to grant it any other access in the screen above. Consider this account as a new Google account you can use to grant folder access later.

In order for Fastlane to perform actions on behalf of the service account you need to create a JSON key by selecting the option manage keys from the three dot menu below:

Step 3: Rename and Move Service Account Key

Rename the service account key to drive_key.json and place it inside the fastlane directory. Remember to add it to the .gitignore so the credential is not accidentally commited to GIT.

Step 4: Create Drive + Share with Service Account

Create a Google Drive as you normally would, and share it (with write access) with the newly created service account’s email.

Take note of the folder ID. It will be the long random character sequence at the end of the URL when you open the folder in the Google Drive web interface.

Step 5: Configure Fastlane

The final step is to edit the Fastfile to use the Google drive upload instead of the regular play console upload.

It should look something like the one below:

default_platform(:android)
platform :android do
desc "Deploy a new version to the Google Play - Alpha"
lane :deploy_alpha do
gradle(task: "clean bundleRelease -PMYAPP_UPLOAD_STORE_PASSWORD=#{ENV['STORE_PASSWORD']} -PMYAPP_UPLOAD_KEY_PASSWORD=#{ENV['KEY_PASSWORD']}")
upload_to_google_drive(
drive_keyfile: 'drive_key.json',
service_account: true,
folder_id: 'ID_OF_THE_FOLDER_GOES_HERE',
upload_files: ['app/build/outputs/bundle/staging/app-staging.aab']
)
end
end

Conclusion

We have created a simple modification to the usual Fastlane upload of an Android app that uses Google Drive as a build repository instead of uploading directly to the Play Console.

This may be useful in cases where your CICD does not have access to the Play Account for direct build uploads.

Hope this was helpful! If you need help or are looking to develop new software, reach out at Avantsoft.

--

--

Paulo Carvalho

Want to chat about startups, consulting or engineering? Just send me an email on paulo@avantsoft.com.br.