Generating APK — React Native

samir khanal
Analytics Vidhya
Published in
2 min readMar 24, 2021

We will be using React Native CLI for generating an apk.

First, we need to make sure that the project is running successfully without any errors. Then, generate a private signing key to generate an apk for an React Native app.

Step-1:

We can generate a private signing key using keytool on our project directory as :

sudo keytool -genkey -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

We can change your_key_name with any name we want, as well as your_key_alias. This command prompts us through the following :

Enter your keystore password: 12345Re-enter new password: 12345What is your first and last name? [unknown]: Samir KhanalWhat is the name of your organizational unit? [unknown]: XYZWhat is the name of your organization? [unknown]: XYZWhat is the name of your city or Locality? [unknown]: XYZWhat is the name of your State or Province? [unknown]: XYZWhat is the two-letter country code for this unit? [unknown]: XX

It generates a file named my-release-key.keystore with above credentials.

Step-2:

Now, Let us copy the above generated file(my-release-key.keystore) to android/app directory in our Project folder.

Step-3:

We should edit the file android/gradle.properties and add the followings:

MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystoreMYAPP_UPLOAD_KEY_ALIAS=my-key-aliasMYAPP_UPLOAD_STORE_PASSWORD=*****MYAPP_UPLOAD_KEY_PASSWORD=*****

We should replace ***** with the correct keystore password that we have set before.

Step-4:

Now, We should edit the android/app/build.gradle file in our project folder, and add the signingConfigs just after the defaultConfig{ … } and ‘signingConfig signingConfigs.release’ line at the last of release in buildTypes as shown below.

...android { ...  defaultConfig { ... }  signingConfigs {    release {      if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {      storeFile file(MYAPP_UPLOAD_STORE_FILE)      storePassword MYAPP_UPLOAD_STORE_PASSWORD      keyAlias MYAPP_UPLOAD_KEY_ALIAS      keyPassword MYAPP_UPLOAD_KEY_PASSWORD      }    }  } buildTypes {   release {      ...      signingConfig signingConfigs.release      }   }}...

Now, go to android/ directory of our project and run,

./gradlew assembleRelease

This will generate an apk file at android/app/build/outputs/apk/release/ directory.

By this, we get an apk file of our React Native project which we can publish in google play-store or share with others.

References:

https://reactnative.dev/docs/signed-apk-android

--

--