Tag Archives: Android

React Native Issues

Recently I started learning React Native to build native mobile applications using React JS. I faced lots of issues while making my first application run on my Ubuntu desktop. Here I am recording issues I faced and the solutions that worked for me, so that beginners like me don’t have to reinvent the wheel.

A problem occurred configuring project ‘:app’.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
  1. Go to your React native Project -> Android
  2. Create a file local.properties
  3. Open the file
  4. paste your Android SDK path like below
    • in Windows sdk.dir = C:/Users/USERNAME/AppData/Local/Android/sdk
    • in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
    • in linux sdk.dir = /home/USERNAME/Android/Sdk

Replace USERNAME with your user name

Now, Run react-native run-android in your terminal
ENOENT: no such file or directory, open ‘android/app/src/main/assets/index.android.bundle’
Manually create this directory
mkdir android/app/src/main/assets
Unable to load script from assets index.android.bundle
  1. (in project directory) mkdir android/app/src/main/assets
  2. 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
  3. react-native run-android

ou can automate the above steps by placing them in scripts part of package.json like this:

Ref: https://stackoverflow.com/questions/44446523/unable-to-load-script-from-assets-index-android-bundle-on-windows

 

Then you can just execute npm run android-linux from your command line every time.

I will keep updating this as and when I encounter new issues with solutions that worked for me.

Android – Command not found (Ubuntu)

If you encounter this error, it indicates that your environment variables are not properly set. We will add these environment variables by editing “.profile” file present in your home directory.

If you have installed android sdk through Android Studio, it is likely to be present in /home/your_user_name/Android/sdk, otherwise in /home/your_user_name/android-sdk-linux.

If you have installed it through android studio then add following line in your “.profile” file
export ANDROID_HOME=$HOME/your_user_name/Android/sdk

else add this

$ export ANDROID_HOME=~/android-sdk-linux

Then add the paths to the platform-tools and tools sub-directories

export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

You should now be able to run android from the shell. Note that you might need to reopen the terminal to make it work