React Native Error when running React-Native run-android - android

I get this strange error in VScode when I try to execute the command React-native run-android in the terminal.
Also ran react-native doctor and all green checkmarks for Node,yarn, android_home, and android sdk 0 errors
Not sure how to fix these issues as I have tried all suggestions in previous threads. Anyone have this issue that could assist? This is a windows machine.
Error Image

1.first Gradle needed to connect to the internet.
2.cd android
./gradlew clean
./gradlew wrapper
./gradlew -v // to download the new version
3.project app-level build.gradle file:
update version this
com.google.firebase:firebase-analytics
and this
com.google.gms:google-services

Related

React-native run-android is not working because it cant found any emulators macOS

I created react-native project and when I run react-native run-ios it is working perfectly.
But the problem is android.
Whenever I run react-native run-android it gives me this error:
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
After this error it begins to install the app and in the end I get this error.
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 app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
I installed latest java and jdk tools.
I found some solutions on stack overflow and I followed one which suggested to clean Gradlew file in the android folder but it did not work either.
any suggestions please?
My OS is macOS Catalina
Just in case anyone encounters this problem.
I solved it this way
1.ANDROID STUDIO
I went to the android studio and updated all the tools needed for the emulator
2.Android folder inside the project
I went to the android folder of my project, inside of android/app/gradle Gradle-wrapper file and updated distributionUrl to the latest version
3.Clear cache
I ran npm --reset-cache start
4.Final step
After all of this I opened android emulator and ran react-native run-android in my app and it worked

gradlew commands showing no result

I am trying to run following commands on Terminal window of Android Studio, but nothing is coming in result:
ms-macbook-3868:ProjectName my_name$ ./gradlew install
ms-macbook-3868:ProjectName my_name$ ./gradlew bintrayUpload
ms-macbook-3868:ProjectName my_name$
Is this issue with Android Studio?
Please help.

Execution failed for task ':app:compileDebugJavaWithJavac' react native

I am trying to run react native app on my android device like this in cmd
cd C:\Users\User\Desktop\js
react-native run-android
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not find tools.jar
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.243 secs 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/android-setup.html
Can anyone please tell me how to fix this problem?
Use the following step once, it may help you:
step 1: open cmd through administrator
step 2: navigate to your application by cd <path to your project>
step 3: run this command: ./gradlew clean
step 4: react-native run-android
Have you installed JDK and Android SDK properly? Are the JAVA_HOME and ANDROID_HOME properly placed in your environment variables?
I faced this issue while working on react-native project on Linux.
In my case issue occured because I linked some external plugin and then removed it without unlink. In that case you can attentively read your console error message. It should point to place that source an error.
The solution if ur version of react-native >= 0.61.0. It shows error as when we add any plugin and use link command then it makes changes in android and ios folder. But when we remove plugin, it gets removed from package.json but inside android changes are not reverted and it gives error. So use below command to generate android folder again.
I hope it will solve the error-
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
If you are working with react native, just make sure you set up environment variables correctly for java compiler.
after this goto package.json file in your project:
change this:
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
to:
"react-native": "0.57.5",
save and run npm install
Source: https://github.com/facebook/react-native/issues/21722

react-native run-android command failed, but gradlew installDebug work

I'm using react-native 0.43.3 on OSX.
I tried to running app on Android and get message
react-native run-android
Scanning 568 folders for symlinks in /Users/ruci.k/project/mayacrew/supermembers/supermembers/node_modules (5ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
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/android-setup.html
./gradlew installDebug gave me some errors and fixed it all.
Finally build get successed and app is working on Android device.
But react-native run-android command still not work.
Only ./gradlew installDebug command work.
Is there anything can I check to use react-native run-android command?
I can't understand how could it happened.
Running
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
worked for me
Run the following command
chmod 755 android/gradlew
inside your app root folder
then run
react-native run-android
After you create your react native app ,try
sudo chmod -R 777 node-modules
sudo chmod -R 777 android
export ANDROID_HOME=~/Library/Android/sdk
now run
react-native run-android
Try removing android,ios folders and then do react-native upgrade then try again react-native run-android After that if you get an error like
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
then create a file named local.properties inside the folder
android
and insert the following line sdk.dir =/path/to/Android/Sdk After this everything should be fine
Note: If you have made some changes in android/ios folder please keep its backup before removing the folders
cd android && sudo ./gradlew clean
This worked for me. Try it out and let me know if it helps folks
I have faced the same issue when I have imported the project from the GitHub.
Follow the below steps to run your react-native project in the Android device from the MAC OS
Remove the 'node_modules' folder from the root project.
Run the below command in the project root folder.
npm install
Move to the android folder in the project root folder.
cd android
Run the following commands one after another to give permissions to gradlew file.
chmod +x ./gradlew
xattr -l ./gradlew
xattr -d com.apple.quarantine ./gradlew
Now, come back to project root folder and run the project in android device.
react-native run-android
Now you can see the launched application on your connected Android device/emulator.
In Ubuntu, I have used this command and it worked for me:
sudo react-native run-android
I had the same issue, and just opened the project in android studio, and that's all. Solved!
this issue come from two reasons
1- Permission issue
How to Fix it
sudo react-native run-android
Or
chmod 755 android/gradlew
2- Mismatch java version with Gradle
make sure you are using Java 8 as $JAVA_HOME environment variable
depending on which terminal you are using to run your code at
For zsh shell, export $JAVA_HOME at ~/.zshenv or ~/.zshrc.
For bash shell, export $JAVA_HOME at ~/.bash_profile or ~/.bashrc.
get installed JDK by this command
/usr/libexec/java_home -V
example for using zsh
vi ~/.zshrc
// paste the java export inside it
export JAVA_HOME="JDK_8_Path_from_previous command"
to save your change
:x
make sure your changes applied
source ~/.zshrc
now for testing
echo $JAVA_HOME
You must change your build.gradle:
compileSdkVersion 28
buildToolsVersion "28.0.2"
minSdkVersion 16
targetSdkVersion 27
and add this line:
implementation "com.android.support:appcompat-v7:28.0.0"
Check whether your emulator is connected or not:
set ANDROID_HOME path: E:\android-sdk-windows
set path D:C:\Program Files\nodejs;C:\Program Files\Java\jdk1.8.0_111\bin;E:\android-sdk-windows\platform-tools
go to folder android in terminal
gradlew clean
run react-native run-android
maybe install watchman?
https://github.com/facebook/react-native/issues/10056
Otherwise, for me I actually use 'npm start' inside of the folder. npm will know to run the right command to start react native because it's in a react native directory.
So what i did was to download this jar file from: 1: https://drive.google.com/file/d/1MHSJx-_0RHRzlrXBLAePKeWKQteke0Um/view?usp=sharing and placed it inside android/gradle/wrapper then i went back to the project directory and did npm install i then changed directory to android by doing: cd android then i ran the following commands
chmod +x ./gradlew
xattr -l ./gradlew
Now i went back to the project directory and ran react-native run-android
Go to C:\Users\ [username]
Rename or delete ".gradle"
Then run "react-native run-android"
So here are the three solution for this bug , from which one will most probably solve your issue :
1: Adding local.properties file in your android folder
https://stackoverflow.com/questions/32634352/react-native-android-build-failed-sdk-location-not-found
2: Try deleting .gradle file and then build (react-native run-android)
3: Might be possible that under SDK tools NDK(side by side) and CMake are not installed .
Steps for the same is
Android Studio which include direction for opening sdk manager
Open android folder in Android Studio
Click on the SDK Manager (which is at the third position from the top left )
After opening SDK manager you have to go to SDK Tools Installation image for NDK and CMake
Under SDK Tools select NDK(side by side) and CMake and press the okay button and let the installation complete .
After the close the Android Studio and react-native run-android.
1 . you should have space in your phone
2 . developer option on
3 . USB debugging option also on
4 . check "adb devices" devices is connected or not
I have to perform these steps to get it running.
First install dos2unix
Run dos2unix ./gradlew inside android folder
then run ./gradlew clean
at last run react-native run-android.
For me, this had to do with running low on RAM om my Mac.
in gradle.properties put -XX:MaxPermSize=4096
for example like this:
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m
After that, it runs again.
What worked for me is,
Uninstalling the previous installed app version on the emulator device, and running react-native run-android after.
Check the error messages carefully. It will give a clue to what went wrong. In my case, after installing expo in my react-native project, the MainApplication.java got corrupted. I made a comparison with the a backup (you can check an earlier working commit), then removed the erroring lines.
After this, it worked.

Could not find method include() for arguments [:app] on root project Android Studio

I am trying to import an android project to Android studio,after importing and then clicking on the green run button :
FAILURE: Build failed with an exception.
Where:
Build file
'/home/myusername/prjcts/nomadx/settings.gradle' line: 1
What went wrong:
A problem occurred evaluating root project 'nomadx'.
Could not find method include() for arguments [:app] on root project 'nomadx'.
The content of the file settings.gradle
include ':app'
I solved the problem ; for those who have the same issue : You should build the gradle with the Terminal/console not with Android studio :
./gradlew assembleRelease
After getting this error on first setup:
capacitor.settings.gradle' as it does not exist
..I used two commands from that page: npx cap sync android and npm install --save #capacitor/core #capacitor/cli. I'm not sure which one fixed that error, but it gave me the one on this page. I didnt want to build Gradle again when Android Studio should have it, so I restarted it and it started downloading a bunch of Gradle stuff to: /home/user/.gradle. It then prompted me to upgrade Gradle.
I then got a similar error to the OP Could not find method include() for arguments [:app] on root project 'android' of type org.gradle.api.Project..
So finally running the above ./gradlew assembleRelease, this error was shown:
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager. All licenses can be accepted using the sdkmanager command line tool: sdkmanager.bat --licenses
I installed SDK sudo snap install android-sdk but didnt have it. Installed with sudo apt install sdkmanager and then sudo sdkmanager --licences (y) to accept.. and got the same error. Found sdkmanager under Tools in AStudio. Tried to update there, but failed. Opened with sudo android-studio, had to select /home/user/.config/Google/AndroidStudioX.Y

Categories

Resources