Fastlane for Android — Automate Everything (Part 3)
Here we are again! In this section I will talk about Fastlane Beta Deployment. You can go to read my previous blog post Part 1 and Part 2 first before starting this blog.
Beta Deployment
Fastlane provide a lot of beta testing services. So I will use Crashlytics (Fabric) for beta testing service. More information about additional supported beta testing services can be found in the list of “Beta” actions.
Building your app
Now let’s create lane name beta
for building apk and deploy to Crashlytics.
To get your API token, open the organizations setting page and click on the API Key and Build Secret.
Make sure you have set up Fabric to your project. To set up Fabric you can follow this instruction.
Now let’s run our lane $ bundle exec fastlane beta
That’s all about Beta Deployment. For more about Beta Deployment, you can go here. Next, we will move to Play Store Deployment. Finally we come to the final part of Fastlane. 😲
Play Store Deployment
To upload your apk and metadata to Google Play Store, Fastlane uses a tool called supply. Becuase supply needs authentication information from Google, so make sure you’ve done Setting up supply from Fastlane Docs or following the steps below:
Setting up supply
supply is a fastlane tool that uploads app metadata, screenshots and binaries to Google Play. You can also select tracks for builds and promote builds to production!
Setting it up requires downloading a credentials file from your Google Developer Service Account.
Collect your Google credentials
- Open the Google Play Console
- Click Settings menu entry, followed by API access
- Click CREATE SERVICE ACCOUNT button
4. Click on Google API Console which open a new tab/window:
- Click the CREATE SERVICE ACCOUNT button at the top of Google Developer Console
- Provide a Service account name and click Create
- Click Select a role and Service Accounts > Service Account User > Continue
- Click on CREATE KEY > JSON > Create your json file will downloaded to your computer
- Back one the Google Play Console, Click DONE
- Click on Grant Access for the newly added service account.
- Choose Release Manager (or alternative Project Lead) from the Role dropdown.
Note that choosing Release Manager grant access to the production track and all other tracks. Choosing Project Lead grant access to update all tracks except the production track
- Click ADD USER to close the dialog.
That’s it. Now you can use josn file with fastlane.
Configure supply
Edit your fastlane/Appfile
and change the json_key_file
line to have the path of your credentials file:
Fetch your app metadata
If your app has been created on the Google Play Developer Console, you’re ready to start using supply
to manage it. Run:
$ bundle exec fastlane supply init
And all of your current Google Play Store metadata will be downloaded to fastlane/metadata/android
Note: Due to limitation of the Google Play API,
supply
can’t download existing screenshots or videos.
Back to Play Store Deployment. When you finish setting up supply, we can now deploy app to Google Play Developer Console using fastlane.
Now create lane deploy
, when we run that lane it will create sign apk and deploy to Google Play. (To create sign apk you can look at Sign your app)
upload_to_play_store
is Fastlane action. track
is its parameter which indicate that whether you want to release your apk to Beta or Production. you can see its available parameter via:
$ bundle exec fastlane action upload_to_play_store
To see all fastlane action, you can go to Available Actions.
Now let’s run lane deploy
via: $ bundle exec fastlane deploy
.
After it run success, you can go to Google Play Console > Click on your app > App Release > Your track > EDIT RELEASE
In Android App Bundles and APKs to add you will see your apk that you have built or if you don’t see your apk, you can click on ADD FROM LIBRARY.
Note: You have to create your app in Google Play Developer Console first and add your first apk to your app so it can recognize your
ApplicationId
.
That’s all about Fastlane Play Store Deployment. You can read more about it here.
Finally, we have come to and end about Fastlane. Next, I will implement CircleCI for android. Hopefully you aren’t getting any error following these blogs. So if you have any problem, please let me know! 👂 Thanks. 👍