In react-native, the SHA key is very important, especially when you deal with Google services and other services. If you are planning to create an apk file the first step is you need to create a SHA signed keystore file.
Here I am going to describe to you the best way to generate the release SHA key for React Native. So that you can create it in a single step. Let’s create an SHA key step by step.
Step 1: Open the command prompt or git bash inside your project folder.
Step 2: Keystore file is placed in the app directory. So we need to go into that directory. To go to the app directory. you can simply use the below command.
Step 3: Run the below command to generate the release SHA key
Before running the below command you need to create a file name with keystore extension inside the app directory. Then add that file inside app/build.gradle as shown below.
After doing the setup. Run the command given below.
keytool -list -v -keystore ./{Your_keystore_file_name} -alias {your_key_alias}
where replace {Your_keystore_file_name} by your release Keystore filename and {your_key_alias} by keyAlias
In My case my release Keystore file name is “your_key_name.keystore” and the alias name is “your_key_alias”
When you run the above command you are asked for a password. Enter the keyPassword of your Keystore file. Then hit enter you can get the SHA1 and SHA256 keys.
Alternative Way:
You can also create a directly signed keystore file and then add it to the app/build.gradle file. To do this, first, you need to run the command given below in the app directory.
keytool -genkeypair -v -storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
This command creates a my-upload-key.keystore inside the app directory with the my-key-alias alias. Then you can use the file in your app/build.gradle file.
For more, You can follow the official documentation.
I hope these instructions helped you. If you get any issues then you can leave a comment or follow the below video tutorial.
Have a wonderful Day 🙏🙏