native_modules.gradle file is deleting as soon as react-redux is installed - react-native

I have created an app in react native for my project. When I copy my projects file in the app folder then run the app it said that in node_module react-redux does not exist then I installed react-redux using npm install react-redux#7.0.3 in my app folder after that when I run run-android command in command prompt for this project it is telling that -
Could not read script 'E:\AppFolder\MyApp\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' as it does not exist. .
After that, I wiped the data of emulator and run run-android, but it is still giving me the same error and app is not installing in the emulator.
Here is the error which command prompt is displaying :
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Settings file 'E:\AppFolder\MyApp\android\settings.gradle' line: 4
* What went wrong:
A problem occurred evaluating settings 'TribeBond'.
> Could not read script 'E:\AppFolder\MyApp\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' as it 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 1m 10s
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.```

Here I follow these steps to solve my problem-
I build a new app and run it using react-native run-android command.
Then I installed all dependencies one by one, which is going to use in the app.
Then run npm install command in the project.
After that, I re-build the app using react-native run-android.
And Tada! the app is re-built without any error.

Related

react-native not working on physical device

I am new in react native so please help me start with that .I just create my first react-native project by using this command
npx react-native init AwesomeProject
I already install android studio and add path of sdk in environment. Also done with developer option in my android. When I run that command
npx react-native run-android
it gives me a lot of errors like that
* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> 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 'E:\react_native\AwesomeProject\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 7s
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
Go to the android/ directory of your react-native project
Create a file called local.properties with this line:
sdk.dir = /Users/USERNAME/Library/Android/sdk
Where USERNAME is your macOS username
More Info found here

React native apk generate

raushan#raushan:~/bigbuilder/android$ ./gradlew assembleRelease
FAILURE: Build failed with an exception.
Where:
Settings file '/home/raushan/bigbuilder/android/settings.gradle' line: 4
What went wrong:
A problem occurred evaluating settings 'bigbuilder'.
Could not read script '/home/raushan/bigbuilder/node_modules/#react-native-community/cli-platform-android/native_modules.gradle' as it 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 1s
Can some one please suggest what to do now. I am new to react native.
The new error is with linking resources,
one or more of the packages you added to your project (for example by typing yarn add react-native-splash-screen) is not linked, please when add a new package read the documentation well to see if there is more steps to link it with android or ios.
try npx react-native link to link the packages you added to your project, and the run android build by typing npx react-native run-android, if did not work try resetting the cache, first stop the running node server the type npx react-native start --reset-cache
if the same error still appears you need to see the manual linking steps in the package you added, and I think it is named "splash_screen"

Issue while running "npx react-native run-android". How to solve it?

Created a project using npx react-native init AwesomeProject. While running npx react-native run-android in other terminal, I am getting the following error. I tried to follow React Native CLI Quickstart in https://reactnative.dev/docs/environment-setup. I have installed python2, openjdk8, nodejs separately, later deleted them and reinstalled using chocolatey. I have reinstalled AndroidSDK tools, AVD multiple times still getting the same error.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
'C:\Users\Raja' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
'C:\Users\Raja' is not recognized as an internal or external command,
operable program or batch file.
'C:\Users\Raja' is not recognized as an internal or external command,
operable program or batch file.
error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
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)
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\Raja Naveen\Desktop\AwesomeProject\android\app\build.gradle' line: 84
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not open dsl remapped class cache for 7f1u5qpw1jm8dwv3ri20amyrz (C:\Users\Raja Naveen\.gradle\caches\6.2\scripts-remapped\react_dysq7qqrljy3c2uubmf33rsun\7f1u5qpw1jm8dwv3ri20amyrz\dslcf39471ad2848fb82befe662c0627ed4).
> 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified.
* 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 6m 33s
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```
You need to set the ANDROID_HOME & JAVA_HOME in your environments variables if you are in Windows and in either the bashrc or the zshr if you are using a Mac
JAVA_HOME => C:\Program Files\OpenJDK\openjdk-8u262-b10
ANDROID_HOME => C:\Users\laptopName\AppData\Local\Android\Sdk>
P.S: On Windows just enter env in the search bar and click on the first tab then click on New and add those then you are good to go.
Make sure you have added the android SDK paths in the enivironment varailble"
export ANDROID_HOME=$HOME/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
EDIT:
Make sure you have either a running emulator by creating one in Android studio or connected physical devices with USB debugging turned on.
I think
> compileSdkVersion is not specified.
is problem.
Add
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
in build.gradle

I can't open an existing react-native project

I get the following error when I run this command
react-native run-android
Configure project :react-native-onesignal
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot C:\Users\VO\Desktop\xxxx\xxxx\node_modules\react-native\android
FAILURE: Build failed with an exception.
What went wrong:
Task installDebug' not found in project ':app'.
Try:
Run gradlew tasks to get a list of available tasks. 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
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.4.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 4s
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.
First check these:
Check that you have installed all your dependencies correctly or not.
react-native-webview and other plugins giving error then try to fix it.
Gradle version are important for specific plugin usage so check it also that you are using supported Gradle version.
Follow these steps:
Close all metro bundles
watchman watch-del-all && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
open Android Studio and open yourprojectname/android
Let Android Studio sync and if there any sync issue then fix it.
Go to File menu -> invalidate cache and restart
Before react-native run-android try to check you have open device or emulator
Check it with adb devices
Now try once.

react-native run-android doesn't build

I'm totally new in react-native and have an Android emulator running but it doesn't build react-native & shows this error...
what should i do?
FAILURE: Build failed with an exception.
What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
Could not download appcompat-v7.aar (com.android.support:appcompat-v7:28.0.0)
Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/28.0.0/appcompat-v7-28.0.0.aar'.
Connection reset
Could not download support-fragment.aar (com.android.support:support-fragment:28.0.0)
Could not get resource
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 8m 56s
1 actionable task: 1 executed
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.
First of all you should update your node.js
Then run the installation's cammands and for Iranian it's better to use shecan.ir before running build run-android command instead of unworking vpn.
I did these steps and the problem solved.