0
votes

I'm getting this error when I try to run a React Native template app:

FAILURE: Build failed with an exception.

What went wrong: A problem occurred configuring project ':app'. The SDK directory '/home/[USER]/Android/Sdk' does not exist.

I've followed the Get Started Guide by React Native, step by step (https://facebook.github.io/react-native/docs/getting-started)

1. Installed this:

  • brew install node
  • brew install watchman
  • brew tap AdoptOpenJDK/openjdk
  • brew cask install adoptopenjdk8

2. And this:

npm install -g react-native-cli

3. Also did this:

Install Android Studio Download and install Android Studio. Choose a "Custom" setup when prompted to select an installation type. Make sure the boxes next to all of the following are checked:

Android SDK Android SDK Platform Performance (Intel ® HAXM) (See here for AMD) Android Virtual Device

I did it making sure to install these:

  • Android 9 (Pie)
  • Android SDK Platform 28
  • Intel x86 Atom_64 System Image (AND) Google APIs Intel x86 Atom System Image
  • Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build-Tools" entry, then make sure that 28.0.3 is selected.

4. Then, I did this with vim $HOME/.bash_profile

Add the following lines to your $HOME/.bash_profile or $HOME/.bashrc config file:

  • 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

(Do not copy paste the bullets)

BUT

I did not get this:

Type source $HOME/.bash_profile to load the config into your current shell. Verify that ANDROID_HOME has been added to your path by running echo $PATH.

When I do echo $PATH, I see this:

/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/hectorgonzalezsanchez/Library/Android/sdk/emulator:/Users/hectorgonzalezsanchez/Library/Android/sdk/tools:/Users/hectorgonzalezsanchez/Library/Android/sdk/tools/bin:/Users/hectorgonzalezsanchez/Library/Android/sdk/platform-tools

When I do vim $HOME/.bash_profile, I see this:

Setting PATH for Python 3.7 The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}" export PATH

Your previous /Users/hectorgonzalezsanchez/.bash_profile file was backed up as /Users/hectorgonzalezsanchez/.bash_profile.macports-saved_2019-08-15_at_13:26:28

MacPorts Installer addition on 2019-08-15_at_13:26:28: adding an appropriate PATH variable for use with MacPorts. export PATH="/opt/local/bin:/opt/local/sbin:$PATH" Finished adapting your PATH environment variable for use with MacPorts.

Adding ANDROID_HOME enviroment variable

  • 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

(Do not copy paste the bullets)

When I do echo $HOME, I see this:

/Users/hectorgonzalezsanchez

I created an app:

react-native init FirstApp

And ran it with iOS:

'cd FirstApp react-native run-ios'

AND WAS SUCCESFUL (no problem in iPhone X with XCode)

BUT when I do:

'cd FirstApp' 'react-native run-android'

I get this error message:

What went wrong: A problem occurred configuring project ':app'. The SDK directory '/home/[USER]/Android/Sdk' does not exist.

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Get more help at https://help.gradle.org

BUILD FAILED in 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

1
Welcome to StackOverflow. Congrats on the success with your journey. However, StackOverflow does not work like a blog. So, you definitely want to at least separate your question from your answer. You can answer your question yourself; sometimes it is even encouraged.Anton Menshov
Please separate the problem from the solution.hong developer
Thanks guys, I have separated question from answerhgs1979

1 Answers

0
votes

I tried several "solutions" given in other threads, as making a local.properties in the FirstApp/android/ folder as follows:

sdk.dir = /Users/hectorgonzalezsanchez/Library/Android/Sdk

**At this point I realized that I did not set up the virtual device properly in Android Studio before running...

I did this EXACTLY as it is written, and was a TOTAL SUCCESS!!!!!**

Using a virtual device If you use Android Studio to open ./AwesomeProject/android, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this:

Android Studio AVD Manager

If you have just installed Android Studio, you will likely need to create a new AVD. Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the Pie API Level 28 image.

If you don't have HAXM installed, follow these instructions to set it up, then go back to the AVD Manager.

Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step.

(WAIT until the Android virtual device interface is initated and fully operative to run the following)

cd FirstApp react-native run-android

TADAAAAA

In my path to describe my actions here I found the solutions myself.

Thanks, Stackoverflow.