[English] React Native Compile to Android — Make it Easy Way

Garry Priambudi
React Native Zone - English
2 min readMay 8, 2018
Build React Native to Android

Want to read this tutorial in Indonesian?

Compile from React Native to Android, need to configure many things. But here we do not discuss the configuration. We assume you have successfully compiled the .apk file but maybe in your own way.

Here I want to share a few tips to speed up our compile without copy-paste or typing long commands. This tips I got it from my friend, Gattigaga Hayyuta Dewa. A pretty expert in JavaScript. Personal website owned is also very cool http://gattigaga.com/.

For example when you want to compile release to android, we need to run ./gradlew assembleRelease. Early learn React Native, before this step, I always do bundle android in order to standalone. Apparently it’s only done if we want to create a debug compile version only. For release we can do it without having to bundle android.

In the short way, we can speed up our compile release with command from my tips. Give keystore to apk and run zipalign in Android SDK directory.

In the package.json file we added some commands like this

{
...
"scripts": {
...
"buildDebug": "(cd android && ./gradlew clean && ./gradlew assembleDebug)",
"buildRelease": "(cd android && ./gradlew clean && ./gradlew assembleRelease)",
"sign": "jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore dcash.keystore android/app/build/outputs/apk/app-release-unsigned.apk alias_name",
"zip": "~/Library/Android/Sdk/build-tools/23.0.1/zipalign -v 4 android/app/build/outputs/apk/app-release-unsigned.apk android/app/build/outputs/apk/app-release.apk"
},
...
}

Added to the scripts section: buildDebug, buildRelease, sign, and zip. This will help us to compile release .apk file until ready to upload

  • buildDebug to compile .apk file to the debug version. But very rarely do I, because it is better to run with react-native run-android
  • buildRelease for compile .apk file to release version. Once an apk file, it still can’t be used. It still has to be given keystore and run zipalign in the Android SDK directory.
  • sign for provide keystore to the release .apk file. Don’t forget to change the APK file directory and Keystore according to the file path you have
  • zip for runs the zipalign command in the Android SDK directory to the release .apk file. Don’t forget to change the directory of Android SDK and APK file according to the file path you have

To run each of these commands, we run through the terminal / command prompt. Don’t forget go to the React Native project root directory.

npm run-script buildRelease
npm run-script sign
npm run-script zip

Automatic APK file release version is ready for upload to Google PlayStore.

Reference : https://gattigaga.com/

That it all and thank you. Hope can be useful :)

Write the topic idea or request topic you are currently learning about React Native. Contribute your idea or request here http://bit.ly/RequestTopicReactNative

--

--

Garry Priambudi
React Native Zone - English

CTO as a services, Product Manager with Fullstack Background, Geeks. Father and Husband with love.