10

I am creating react native app for mobile application. I am fully new in building react native app. I am using ubuntu for creating the app and following below link to create the app. https://facebook.github.io/react-native/docs/getting-started . Can anyone please solve the issue ?

At below stage I am getting error:

cd AwesomeProject
npx react-native run-android

Error in my command line:

All-Series:~/Projects_App/AwesomeProject$ npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
/bin/sh: 1: adb: not found
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...
> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
13 actionable tasks: 4 executed, 9 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.

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

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

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.

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

    at checkExecSyncError (child_process.js:621:11)
    at execFileSync (child_process.js:639:15)
    at runOnAllDevices (/home/rupeevest/Projects_App/AwesomeProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Priyanko
  • 318
  • 1
  • 5
  • 13

5 Answers5

5

Go to your react-native Project then go to android directory and create a file with this name

local.properties

If you are on Windows open the file and paste your Android SDK path like this:

sdk.dir=C:\\Users\\UserName\\AppData\\Local\\Android\\sdk

I found that answer right here

F.decouv
  • 53
  • 1
  • 6
2

A quick fix I use when I hit similar issues is run

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

then make sure your emulator is open and run react-native run-android again

DCQ
  • 111
  • 6
2

What helped me was to open the project in Android Studio and press the play button after selecting the emulator from the emulator dropdown list next to it.

Also if for some reason that emulator is throwing an error, try installing another one with a different phone. Hope this helps someone!

Samir K
  • 91
  • 2
  • 11
1

For me putting the emulator directory under the SDK into PATH solved the problem.

SushiWaUmai
  • 348
  • 6
  • 20
0
Hello users!
I had many problems while installing 'react native's CLI Quick start',
Mainly because, This was my first attempt.

########################## Note: Linux is case sensitive  ##########################

I am an UBUNTU 22.04 user

My system now has:

[java --version]
openjdk 18.0.2-ea 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode, sharing)

[npm -v]
[
  9.2.0
  To download:
     sudo npm install -g npm@9.2.0
]
[node -v]
[
  v19.2.0
]

[error]
[
    emulator not found,
    SDK error,
    gradel related error
]
[solution worked for me)
[
    [installing jdk 18]
    [
        Terminal:
        sudo apt install openjdk-18-jre-headless
    ],
    [Fixing Sdk path]
    [
        export ANDROID_SDK_ROOT=$HOME/Library/Android/Sdk
        export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
        export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
        
        above line says that 'In home directory, There is folder named(Library),
        Which has Android and And ANDROID FOLDER has sdk folder'
        
        Which was wrong, in my case,
        My SDK folder was in $HOME/Android/Sdk
        
        So i changed 
        
        export ANDROID_SDK_ROOT=$HOME/Library/Android/Sdk
        ================== TO ============================
        
        export ANDROID_SDK_ROOT=$HOME/Android/Sdk
        
        How to check if it is main error?
        Type in terminal:
            $HOME/Library/Android/Sdk
        If Result is:
            bash: /home/rambo/Library/Android/Sdk: No such file or directory
        Than you too need to fix the path.
        
        
    ],
    [Fixing watchman]
    [
        Watchman error came because,
        It needed other things to make it work,
        I fixed it with:
            sudo apt install  libgflags2.2  libgoogle-glog0v5 libboost-context1.74.0 libdouble-conversion3  libsnappy1v5
            sudo dpkg -i  watchmanFileName.deb 
    ],
]
  • 1
    You need to change SDK path of $HOME/.bash_profile or $HOME/.bashrc (if you are using zsh then ~/.zprofile or ~/.zshrc) config file: – Relaxing Music Dec 11 '22 at 16:02