Day078 — How to build your React Native

Jacky Tsang
2 min readMay 20, 2019

--

There are two ways to build a React Native application.

  1. with expo-cli
  2. with react-native-cli

I use the second method to build an android app. That kind of app is called an ejected app, which means it is ejected from the expo eco-system. It is when you want to use a library that requires you to run react-native link to link your library. More on ejecting.

Steps to build apk or ipa

  1. npm install
  2. react-native eject
  3. react-native link
  4. react-native run-android or react-native run-ios

Important notes

  1. make sure you have java 8 jdk installed. instructions
  2. make sure you have android sdk installed and its path correctly configured. instructions
  3. run chmod 755 android/gradlew if encounter this issue
  4. set android path

Download JDK

Otherwise below error occurs.

* What went wrong:
Could not determine java version from '12.0.1'.

Set android path

add below to .bash_profile or .zshrc

export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools

To run React Native on Windows

  1. clone repo
  2. run npm install -g react-native-cli to install react-native-cli globally
  3. run yarn install
  4. run yarn start on one terminal and run yarn start-android on another terminal

To solve “SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.” problem

  1. create local.properties under ./android
  2. write sdk.dir=C\:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk to define location of android sdk. ref: StackOverflow

To solve “Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_201 contains a valid JDK installation” problem

  1. reinstall jdk 8 — Java SE Development Kit 8u201, ref StackOverflow

To solve “com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.agwmmmusic signatures do not match previously installed version; ignoring!” problem

  1. uninstall any previously built app on device

To solve “‘adb’ is not recognized as an internal or external command, operable program or batch file.” problem

  1. put C:\Users\USERNAME\AppData\Local\Android\Sdk\platform-tools to Path in Environment Variables

--

--

No responses yet