Can't run react-native run-android? - react-native

I'v followed the steps from https://reactnative.dev/docs/environment-setup. I can start the phone emulator from AVD Manager in Android Studio and I can run react-native start without problems. When i enter in another terminal react-native run-android I get the following error:
info Running jetifier to migrate libraries to AndroidX. You can
disable it using "--no-jetifier" flag. (node:9612) Warning: Accessing
non-existent property 'padLevels' of module exports inside circular
dependency (Use node --trace-warnings ... to show where the warning
was created) Jetifier found 967 file(s) to forward-jetify. Using 16
workers... info Starting JS server... info Launching emulator... info
Successfully launched emulator. info Installing the app... Downloading
file:/D:/App/AwesomeProject/android/gradle/wrapper/services.gradle.org/distributions/gradle-6.7-all.zip
Exception in thread "main" java.io.FileNotFoundException:
D:\App\AwesomeProject\android\gradle\wrapper\services.gradle.org\distributions\gradle-6.7-all.zip
(The system cannot find the path specified)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:211)
at java.base/java.io.FileInputStream.(FileInputStream.java:153)
at java.base/java.io.FileInputStream.(FileInputStream.java:108)
at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:189)
at org.gradle.wrapper.Download.downloadInternal(Download.java:78)
at org.gradle.wrapper.Download.download(Download.java:63)
at org.gradle.wrapper.Install$1.call(Install.java:68)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)
error Failed to install the app. Make sure you have the Android
development environment set up:
https://reactnative.dev/docs/environment-setup. Run CLI with --verbose
flag for more details. Error: Command failed: gradlew.bat
app:installDebug -PreactNativeDevServerPort=8081 Exception in thread
"main" java.io.FileNotFoundException:
D:\App\AwesomeProject\android\gradle\wrapper\services.gradle.org\distributions\gradle-6.7-all.zip
(The system cannot find the path specified)
And if I run react-native info I get:
info Fetching system and libraries information... (node:14952)
Warning: Accessing non-existent property 'padLevels' of module exports
inside circular dependency (Use node --trace-warnings ... to show
where the warning was created) System:
OS: Windows 10 10.0.19041
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 23.88 GB / 31.90 GB Binaries:
Node: 14.15.0 - D:\nodejs\node.EXE
Yarn: Not Found
npm: 6.14.8 - D:\nodejs\npm.CMD
Watchman: Not Found SDKs:
Android SDK: Not Found
Windows SDK: Not Found IDEs:
Android Studio: Not Found
Visual Studio: Not Found Languages:
Java: 15.0.1
Python: 3.9.0 npmPackages:
#react-native-community/cli: ^4.13.0 => 4.13.0
react: 16.13.1 => 16.13.1
react-native: 0.63.3 => 0.63.3
react-native-windows: Not Found npmGlobalPackages:
react-native: Not Found
I'v tried a lot of things but nothing seems to work.

Looks like an issue with gradle version.
Do these.
remove android/.gradle folder.
open /android in android studio
goto File->Project Structure->Project and change Gradle Version to more recent one. and wait for it to complete gralde sync task.
run react-native run-android after this.

Related

React Native Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0

after installing some packages like react-native-safe-area-context or react-native-screen, I always have this problem: can't run the app
when I run yarn android:
> Configure project :react-native-async-storage_async-storage
Subproject ':react-native-async-storage_async-storage' has location 'D:\ewm\git\itc\node_modules\#react-native-async-storage\async-storage\android' which is outside of the project root. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0.
> Configure project :react-native-safe-area-context
Subproject ':react-native-safe-area-context' has location 'D:\ewm\git\itc\node_modules\react-native-safe-area-context\android' which is outside of the project root. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0.
> Task :react-native-safe-area-context:compileDebugKotlin
w: D:\ewm\git\itc\node_modules\react-native-safe-area-context\android\src\main\java\com\th3rdwave\safeareacontext\SafeAreaView.kt: (50, 23): 'getter for uiImplementation: UIImplementation!' is deprecated. Deprecated in Java
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
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
* What went wrong:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0
* 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 26s
when I run react-native info:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU # 2.60GHz
Memory: 3.90 GB / 15.96 GB
Binaries:
Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 29, 30, 31, 32
Build Tools: 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0
System Images: android-Tiramisu | Google Play Intel x86 Atom_64
Android NDK: Not Found
Windows SDK:
AllowAllTrustedApps: Disabled
Versions: 10.0.18362.0, 10.0.19041.0
IDEs:
Android Studio: Version 2021.1.0.0 AI-211.7628.21.2111.8193401
Visual Studio: 16.11.32106.194 (Visual Studio Community 2019)
Languages:
Java: 17.0.2
npmPackages:
#react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-windows: Not Found
npmGlobalPackages:
*react-native*: Not Found
use ./gradlew clean to delete all previous build and rebuild
In my case the issue was to do with duplicate files in android resource folders. I used below commands to remove the duplicates.
rm -rf ./android/app/src/main/res/drawable-*
rm -rf ./android/app/src/main/res/raw
See: https://stackoverflow.com/a/57975287/10030693

cli : unable to talk to your watchman

I am new to React Native and I am trying to set up my development environment on Windows 8.1 as described in the official documentation.
But I have a problem
Steps :
react-native init AwesomeProject
cd AwesomeProject
react-native start
The app doesn't start correctly and I have this error :
2020-05-26T18:02:48,578: [cli] unable to talk to your watchman on \\.\pipe\watchman-ME! (No such file or directory)
Watchman: watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2020-05-26T18:02:48,578: [cli] unable to talk to your watchman on \\.\pipe\watchman-ME! (No such file or directory)
So I figured the problem is with watchman
I found the path on this error weird (\\.\pipe\watchman-ME!) because when executing react-native info, I get the following :
System:
OS: Windows 8.1 6.3.9600
CPU: (8) x64 Intel(R) Core(TM) i7-4702MQ CPU # 2.20GHz
Memory: 4.36 GB / 7.93 GB
Binaries:
Node: 13.2.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.19.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.13.1 - C:\Program Files\nodejs\npm.CMD
Watchman: 20200424.164118.0 - C:\Users\ME\AppData\Local\watchman\watchman.EXE
SDKs:
Android SDK:
API Levels: 26, 27, 28, 29
Build Tools: 28.0.3, 29.0.2, 30.0.0
System Images: android-29 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6392135
Languages:
Java: 1.8.0_241 - /c/Program Files/Java/jdk1.8.0_241/bin/javac
Python: 2.7.17 - /c/Python27/python
npmPackages:
#react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
*react-native*: Not Found
Is my configuration correct ? Because I read other posts, issues and the best recommendation was to reinstall watchman and reboot. I did it multiple times but no changes. If that matters I downloaded the latest CI build, extracted it and added it to the path as described in the docs.
But I keep getting the same error, I tried with existing and new projects as well.
EDIT :
When I start the app, I said it doesn't start correctly, what happens is that it actually opens a white screen with a green bar saying Loading from 10.0.2.2:8081 ..., I read about it (example) and I tried every proposed solution, everything seems all right but I keep getting the same error !

Hi guys I keep getting the error ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH

I keep getting
ERROR: JAVA_HOME is not set and no 'java' command could be found in
your PATH
Whenever I try to run react-native code from my terminal to use an android emulator.
I've recently been trying to set up react-native on my laptop through wsl because the virtual box has been giving me trouble using it.
I've set my ANDROID_PATH to C:\Users\username\AppData\Local\Android\Sdk and my JAVA_PATH to D:\Program Files\Java\jdk-13.0.1. But I keep getting the error.
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 8 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...
ERROR: JAVA_HOME is not set and no 'java' command could be found in
your PATH. Please set the JAVA_HOME variable in your environment to
match the location of your Java installation. 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
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (/mnt/c/users/meron/Projects/react/New_project_7/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
I've tried everything but still no luck

Problem encountered in react native run android

I recently installed React Native on my Windows PC and I created a project but when i try with react-native run-android for android emulator it shows me:
C:\ReactNative\testproj>react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 855 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files (x86)\Java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
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.bat app:installDebug -PreactNativeDevServerPort=8081
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (C:\ReactNative\testproj\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:74:39)
at buildAndRun (C:\ReactNative\testproj\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\index.js:158:41)
at then.result (C:\ReactNative\testproj\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\index.js:125:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
Please help
Your JAVA_HOME is set incorrectly, go through the setup again, everything should works...
You can refer to this and check what is missing...

react-native eject error Unrecognized command "eject"

I'm trying to eject my app to generate Android folder. I knew it worked before, but when I type react-native eject in my React Native project's root directory I'm getting:
can-mbp:MyApp can$ react-native eject
warn Your project is using deprecated "rnpm" config that will stop working from next release. Please use a "react-native.config.js" file to configure the React Native CLI. Migration guide: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
warn Package "bugsnag-react-native" is using deprecated "rnpm" config that will stop working from next release. Please notify its maintainers about it.
warn Package "react-native-onesignal" is using deprecated "rnpm" config that will stop working from next release. Please notify its maintainers about it.
warn Package react-native-onesignal has been ignored because it contains invalid configuration. Reason: Unknown option dependency.platforms.ios.sourceDir with value ""./ios"" was found. This is either a typing error or a user mistake. Fixing it will remove this message.
error Unrecognized command "eject".
info Run "react-native --help" to see a list of all available commands.
I've searched for it but every answer points out to that react-native eject is simply the correct form and I couldn't find anything regarding that it doesn't work.
Here is my system info from react-native info command:
System:
OS: macOS 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU # 3.10GHz
Memory: 62.21 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.4.0 - /usr/local/bin/node
Yarn: 1.17.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.0-rc.2 => 0.60.0-rc.2
What am I doing wrong?
Since create-react-native-app is deprecated this functionality is no longer needed.
Due to this pr it's gone!
Personaly I don't like it but run npx react-native init YourProjectName and copy over what's necessary.
Update :
I copied to removed code and made a small package : https://www.npmjs.com/package/react-native-eject
Always working for me, first install in your project
yarn add react-native-eject
and then run
react-native eject
make sure you have install yarn in your pc
Type the following command
npx react-native eject