React Native to Google Play Store with Fastlane

Zalmy Muskal
4 min readNov 20, 2020

--

Before you get started you need to follow the guide on React Native docs to get a signed release APK.

Once that is done you are ready to begin.

Install Fastlane

# Using RubyGems (Preferred method)
sudo gem install fastlane -NV

# Alternatively using Homebrew
brew install fastlane

Once that is done, install the Fastfile.

In your project directory
cd android/
fastlane init
Fastlane will then ask you for your Package Name. You can find it in the AndroidManifest.xml (android/app/src/main/AndroidManifest.xml) on the second line package=”com.packageName” .
You can then skip entering the path to the json secret file (we will get to that again later) by pressing Return.
You will then be asked: Download existing metadata and setup metadata management? (y/n)
Press n. and the Return key for the next two questions.

Setting up Supply (or upload_to_play_store)

Before we begin this part, you might want to upload your app manually to the Play Store without using Fastlane. The first time I tried using Fastlane to connect with the App Store it didn’t work. After Googling to see what could be causing this, I saw that people wrote that you first need to upload manually, wait for app approval, and then try again. After uploading manually and waiting for it to be approved it finally worked.

Now let’s continue.
Go to your Google Play Console.
Under Settings > Developer Account, click on API access.
Under Service Accounts choose ‘Create new service account’.
A modal will open with a link and instructions.

Go to the Google Cloud Platform

Click ‘Create Service Account’

Fill in the details and click ‘Create’
At this point, you can create a private key. The private key is downloaded to your machine and is the only copy of this key. You must keep the private key secure, it will be needed by your application to make API calls using your service account

Click ‘Done’ and check the new account appears in the list.

Follow the instructions. When it comes to filling in the details there are three sections. Service account details, Grant this service account access to project, and Grant users access to this service account.
Under the first one, you will need to fill out a Service Account Name (it can be whatever you want). You can also provide a description if you would like. The Service account ID is made for you automatically.
Under the second one choose the ‘Select a role’ box and scroll down to Service Accounts and click on Service Account User.
Finally, click Done.

On the right-hand side of the Service account that you just created are three dots under the label ‘Action’. Click on it and choose ‘Create key’.
Under key type you want it to be JSON (which is the recommended setting).
Click Create.

It will download the key to your computer. Either remember where it was saved or move it to a better location.
You can now close the Google Cloud Console.
Click done on the modal box back by the Google Play Console.

On the newly created service account click on the Grant Access (it’s smack in middle). It will then take you to the Account permissions tab where you can choose what permissions you want to grant to the service account. I suggest taking a look over it and depending on the role you would like this service account to make (which tracks it should have access to etc.) that is what you should choose.
Finally, choose the Add User on the bottom right.

Connecting Fastlane to the Play Store

Now it's time to check that you didn’t mess up on any of the steps.
Now is also the time to remember where you saved that JSON file from earlier (the key).
Run fastlane run validate_play_store_json_key json_key:/path/to/your/downloaded/file.json to see if it connects.
Once it connects go to your fastlane/Appfile and if the json_key_file line isn’t pointing to your key, update it so that it is.
json_key_file “/path/to/your/downloaded/key.json”

Next, we are going to install a plugin so that we can increment the versionCode so that we don’t have to do it manually each time.
Under the android/ directory do fastlane add_plugin increment_version_code and at the prompt to add plugins to your project select y.

Now all you need to do is update your beta lane in the Fastfile to the following:

desc "Send to beta track Google Play Store"
lane :beta do
increment_version_code(
gradle_file_path: "./app/build.gradle",
)
gradle(task: 'bundle', build_type: 'Release', )
upload_to_play_store(track: 'beta', skip_upload_apk: true)
end

A couple of things to keep in mind.
There are two ways to ways to ‘create’ the app. The first is ‘Assemble’ which makes the app an APK file. The second is ‘Bundle’ which makes the app an aab file. So under task, I have it as bundle (aab file). You can do whatever you want.
Under upload_to_play_store you can choose what track you had in mind. It doesn’t have to be beta.

I love automating things to make life easier, how about you?

I hope this helps and that I was able to give clear instructions. Happy coding!

--

--