React Native – Run the app in Genymotion Android emulator

I am trying to use React Native these days, it works fine in iOS simulator, but when I try to run the app in android emulator, I encountered some problems!

1.The Java SDK issue.

I have developed the android app with flutter before, so I also have installed the android SDK, and I suppose that will be smooth in RN right now, but when I execute below command to try to run the android:

react-native run-android

I got the error that missed the Java SDK, and I need to go to Java website for download it.

2.But after installed the Java SDK, I got another error.

It also need to set the JAVA_HOME and ANDROID_HOME, I use MacOS, so that’s need to set in the ~/.bash_profile file as below:

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Volumes/SourceCodes/androidSDK/android-sdk-macosx

But the problem still not finish… 😨

3. When everything are ok, I still got below error

This error is very strange, I spend many of times for that, fortunately, I found the solution:

1)Create an assets folder in below

yourApp_root/anddroid/app/src/main

2)Execute below command

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

after that it will auto generate the index.android.bundle file in assets folder, and now execute below command for run the android

react-native run-android

The app can be run successfully😁

2,166 total views, 5 views today

Share your vote!


Do you like this post?
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

You may also like...

shares