0

I am new to react native, I was trying to follow an example on how to launch react native app with react native CLI but I keep getting this error in my CMD.

C:\React Native Workspace\RN-CLI\FirstCli>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 863 file(s) to forward-jetify. Using 12 workers...
info Starting JS server...
'adb' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\React Native Workspace\RN-CLI\FirstCli\android\local.properties'.

* 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 10s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\React Native Workspace\RN-CLI\FirstCli\android\local.properties'.

* 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 10s

    at makeError (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\execa\index.js:174:9)
    at C:\React Native Workspace\RN-CLI\FirstCli\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.

I need help with resolving these issues.

Bassel Turky
  • 371
  • 7
  • 15

1 Answers1

2

Assuming that you already have the Android SDK installed, you need to create a file named local.properties at the root of you Android project your-react-native-project-android/ and you should also add it to .gitignore if you are using git.

The file must indicate the path of the SDK on your computer, for macOS for example

local.properties

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Oct 26 14:02:40 CEST 2021
sdk.dir=/Users/username/Library/Android/sdk

If you never installed the SDK, you need to start here

yemd
  • 420
  • 4
  • 15
  • where should I put this line? sdk.dir=/Users/username/Library/Android/sdk – Bassel Turky Feb 07 '22 at 17:02
  • people say paste it inside the folder, how? – Bassel Turky Feb 07 '22 at 17:02
  • 1
    You need to create an empty file named `local.properties` inside the android folder, and then past the content I posted above inside this file, not forgetting to edit the sdk.dir according to your own dir – yemd Feb 07 '22 at 17:10
  • Your solution worked but I got another error: Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @2361f9fc – Bassel Turky Feb 07 '22 at 20:20
  • 1
    If the solution worked for this problem please mark my answer as the accepted answer, your new issue is not related to this StackOverflow question anymore you need to open another one, in the meantime, there is this question that seems to fit your new issue https://stackoverflow.com/questions/67782975/how-to-fix-the-module-java-base-does-not-opens-java-io-to-unnamed-module – yemd Feb 07 '22 at 20:59
  • Just to note, the windows path should be like C\:\Users\\username\\Library\\Android\\sdk – Leslie Wong Mar 19 '22 at 19:10