Photo by Tinh Khuong on Unsplash

You just developed all your react-native code and tested all the application and want to try in your real device?

Now it is time to create Android APK to test your application in real devices.

Android devices require all the applications must be digitally signed with a certificate. I will explain how to create your own certificate and sign your beautiful application with your digital signature.

After you certificate your application you can distribute your application to Google Play Store.

Let’s Start with Generating a signin Key

You can generate a private signing key using keytool . On Windows keytool must be run from C:\Program Files\Java\jdkx.x.x_x\bin .

keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Keytool will ask you

Password

First & last name

Organizational unit

Organization

City or Locality

State or Province

Two-letter Country code

Password is the required one there*

Keytool will create my-release-key.keystore file for you.

Your certificate will be valid for 10000 days.

Signing app with created Key

Now time for placing the keys for required directories.

If you are using mac you can find your jdk path with this command

$ /usr/libexec/java_home

Now cd to that directory with using

$ cd /your/jdk/path

Paste your my-release-key.keystore file there.

Also we need to put that key in to our React Native application open your project root folder and change directory to,

$ cd android/app

Edit now android/gradle.properties file

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore MYAPP_RELEASE_KEY_ALIAS=my-key-alias MYAPP_RELEASE_STORE_PASSWORD=******

MYAPP_RELEASE_KEY_PASSWORD=******

Do not forget to replace ****** with your real store password and key password.

Adding signing config to your app’s gradle config

Open the android/app/build.gradle file.

Add the SigninConfigs release and BuildTypes release as follow.

Edit the file android/app/build.gradle in your project folder, and add the signing config, ...

android {

...

defaultConfig { ... }

signingConfigs {

release {

if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {

storeFile file(MYAPP_RELEASE_STORE_FILE)

storePassword MYAPP_RELEASE_STORE_PASSWORD

keyAlias MYAPP_RELEASE_KEY_ALIAS

keyPassword MYAPP_RELEASE_KEY_PASSWORD

}

}

}

buildTypes {

release {

...

signingConfig signingConfigs.release

}

}

}

...

Everything is ready!

Now lets create our Signed React-Native application APK! 😎

$ cd android

$ ./gradlew assembleRelease

That will create your project apk!

Lets open the application we created in real device

react-native run-android --variant=release

Now you can start testing your application on real android device!

Happy Coding!

Thank you for reading this far. If you enjoyed this post, please share, comment, and press that 👏 a few times (up to 50 times). . . Maybe it will help someone.

Follow me on Medium if you’re interested in more in-depth and informative write-ups like these in the future. 😀

Melih