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

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

Related

react-native run-android Fails MacOS

Complete Console Output is below
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 JS server already running.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 696ms
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/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:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 696ms
at makeError (/Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:174:9)
at /Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (/Users/user/Desktop/sa/MyReactApp/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/Users/user/Desktop/sa/MyReactApp/node_modules/#react-native-community/cli/build/index.js:186:9)
Bash_profile
export ANDROID_HOME=$HOME/Library/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
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_AVD_HOME=$HOME/.android/avd
alias emulator='$ANDROID_SDK_ROOT/tools/emulator'
Requested Attachments
Android SDK Link From Android Studio
SDK Tools Installed
npx #react-native-community/cli doctor Result
Installed Android Emulator
Nexus 6P (Android R and Pie)
New To React Native
it works perfectly on iOS
but it fails to launch in Android Simulator
Tried Ways
npm start
npx react-native run-ios
npx react-native run-android
It is Probably because of JDK version as mention above.
You can verify by running react native doctor
npx #react-native-community/cli doctor
Install JDK 1.8 and setup $JAVA_HOME env variable and try to run the app again.
The error is due to lower version of JDK or JDK not installed.
your problem can be resolved just follow these steps:
To jetify / convert node_modules dependencies to AndroidX
Imagine you have a react-native project. One of your library dependencies converts to AndroidX., and you need to use the new version.
So now you need to convert your app to AndroidX, but many of your react-native libraries ship native Java code and have not updated. How is this done?
First, use Android Studio's refactoring tool to convert your app re: the Android developer docs
npm install --save-dev jetifier
npx jetify
npx react-native run-android (your app should correctly compile and work)
Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again
you can follow this link as well: https://www.npmjs.com/package/jetifier
feel free for any confusion.
This link is the complete solution but here is a little problem if you have win32 but if you have win64 you are good to go.
**https://www.npmjs.com/package/jetifier#do_you_need_this**
hope this answer will be useful for you
feel free for any problem.
The error is due to the version of JDK or JDK not installed.
i think you need to solve in the section:
open the androind folder with android studio
then file-> project structure -> SDK location
and in here you can change, in my case i change the version
before that, for to know what was the error:
i realized what is the problem with this command
npx #react-native-community/cli doctor
i got these errors:
Please make changes as per below to resolve this error.
Install Java SDK version: 14 or above.
JDK Download link: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html
In gradle-wrapper.properties please use grade version 6.3 or above.
For e.g:distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

Task 'installDebug' not found in project ':app' - run-android after creating project

After creating a react native project, I tried to run it on my android device. I enter adb devices into the terminal, I saw my device. I ran react-native run-android. And after a while Task 'installDebug' not found in project ':app' popped up.
Jetifier found 962 file(s) to forward-jetify. Using 4 workers
...info Starting JS server...
'D:\Android\android-sdk\platform-tools' 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...
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.0.1/userguide/command_line_interface.html#sec:command_line_warnings
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
BUILD FAILED in 15s
error Failed to install the app. Make sure you have the Android development environment set up:
https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8
081
FAILURE: Build failed with an exception.
* What went wrong:
Task 'installDebug' not found in project ':app'.
Here is react-native info
info Fetching system and libraries information...
System:
OS: Windows 7 6.1.7601
CPU: (4) x64 Intel(R) Core(TM) i3-2100 CPU # 3.10GHz
Memory: 881.91 MB / 3.97 GB
Binaries:
Node: 10.16.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5014246
Languages:
Python: Not Found
npmPackages:
#react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.0 => 0.62.0
npmGlobalPackages:
*react-native*: Not Found
I ran gradlew tasks and I did not see installDebug under the install tasks. I am sure that I set up the environment variables correctly, including android SDK, JDK. I tried reinstalling react-native. I put the location of my sdk in local.properties under android folder. I ran gradlew installDebug and installDebug not found in root project '[app's name]' appeared. None of the solutions on the internet worked.
Can anyone please help me to sort out this?
Thank you.
I also faced the same problem.
Here is what works for me.
I opened the Android Project in Android Studio.
This can be located at YourReactNativeProjectFolder/android
When I opened this project in Android Studio, it was missing the configuration. Wait for some time and allow Android Studio to configure it and ask you to update the Gradle. Update the Gradle and now you can run your project from the Android Studio or using the command line "npx react-native run-android"
I hope that it will be helpful.
Best
try the following command at the project root:
cd android && ./gradlew assembleDebug && ./gradlew installDebug
The solution is loading the /android folder in the Android Studio and let it update the Gradle. After that you will be able to run react-native run-android
I had the same error.Try the following command, it will show the exact error of the code.
cd android && ./gradlew buildRelease
for me => Mac m1
1.- npx react-native run-android raises metro terminal(stay open metro).
2.- open proyect in Android in the folder android and launch Emulator on Device.(wait....).
3.- later android launch the app and Device error.
4.- in terminal type 'adb reverse tcp:8081 tcp:8081'(in the folder android).
5.- in Device press reload
sorry my English =)
and I hope it will help them

React-Native: error Failed to install the app. Make sure you have an Android emulator running

I just initialized a new React Native project via:
react-native init AwesomeProject
and I am already getting this error:
BUILD FAILED in 3s
error Failed to install the app. Make sure you have an Android emulator running or a device connected. 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:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* 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 3s
at checkExecSyncError (child_process.js:637:11)
at execFileSync (child_process.js:655:13)
at runOnAllDevices (/Users/danale/Projects/engageMobile/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:75:39)
at buildAndRun (/Users/danale/Projects/engageMobile/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:169:41)
at then.result (/Users/danale/Projects/engageMobile/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:135:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
It is a boilerplate app only thus far. I am using zsh and not bash for command line interface.
I also develop in flutter and I do not get this problem, it opens up the Nexus 5X simulator without a hitch.
What could be the problem?
I tried changing permissions, but that is not it.
So apparently I have more experience with ios than android and while react-native run-ios automatically opens up a simulator for you, react-native run-android does not, important point, similar commands, don't do similar things, i.e. open up a simulator.
Once I opened up the application inside of Android Studio and then went to AVD Manager and opened up the simulator for Android Studio and then ran react-native run-android, it worked perfectly.
None of the above worked for me when I start a new project
try this
go to android folder and edit build.gradle
set buildToolsVersion = "23.0.1" mine was 30.0.2 when i changed it to "23.0.1" it started working
In the android folder run
gradlew.bat installDebug
and make sure the Build is successful
That should do it go back to your project folder and run
npm run android
If your nodejs already running or any device is already connected before init project then it wont be considered for react-native.
Make sure your Android simulator is running.
Close ALL terminal window.
Run 'react-native run-android'
It's should open two terminal windows. If you see a same error again,
close the second terminal ( the one where is compile), and run 'npm start' in 1 open terminal.
I ran across the same problem.
Even though my android simulator works fine, once in a while, some corruption occurs, and then react-native run-android throws above error.
One solution that works for me is to close all command prompts, close the virtual devices and re-run them fresh, always worked for me.
Basically open your react native project in android studio, and it will download gradle in android studio instead of the command terminal. then open your command terminal and run the code "npm run android" and it shall work
I think you forgot to create virtual device first.
open android studio application
chose configure icon and then select AVD Manager
create your virtual device here.
after finish, you can run on cmd/terminal npx react-native run-android

ERROR: An error occurred while running subprocess cordova

I build an app on Ionic framework, it works on the browser but when I try to compile it on the emulator I have got this error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\user\AppData\Local\Android\Sdk (DEPRECATED)
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/5.3.1/userguide/gradle_daemon.html
Process command line: C:\Program Files (x86)\Java\jdk1.8.0_201\bin\java.exe -Xmx2048m -Dfile.encoding=windows-1252 -Duser.country=SA -Duser.language=ar -Duser.variant -cp C:\Gradle\gradle-5.3.1\lib\gradle-launcher-5.3.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.3.1
Please read the following process output to find out more:
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
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
C:\Gradle\gradle-5.3.1\bin\gradle: Command failed with exit code 1
[ERROR] An error occurred while running subprocess cordova.
cordova run android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
This is because the path to Android Sdk is not set correctly. Please check the correct path for Sdk, tools, platform-tools, emulator and Android build-tools.
Please, realize that the configuration recommended for Ionic has changed a
bit. Now the notation recommended is as follows:
ANDROID_SDK_ROOT=/home/username/Android/Sdk (recommended setting)
ANDROID_HOME=/home/username/Android/Sdk (DEPRECATED)
In Linux or Mac OS X configure the path into the ~/.bashrc, ~/.bash_profile file:
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/build-tools
At the end, after save the configuration dont forget to do the command:
source ~/.bashrc
or as your case
source ~/.bash_profile
For the Windows users check the global variables.
Try to Run npm cache clean and re-install cordova...worked for me.
I finally found the solution from a related solved topic: The solution is:
ionic platform rm android
ionic platform add android#latest
ionic resources
ionic run android
ionic repair worked for me. Just give it a try and see if that works for you. Good luck!

Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory() react-native. How to fix?

I have the template code for my "Helloworld" app written in javascript and react-native on Windows. I connected my android emulator and wanted to launch the app on it. The following happens when I run "react-native run-android" command. Node.js opens as a separate window and it's written "Loading dependency graph, done". However, in the terminal window, there is following error message:
>User helloworld $ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
>*What went wrong:
Could not create service of type ScriptPluginFactory using
BuildScopeServices.createScriptPluginFactory().
>Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
>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
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
Command failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:616:11)
at Object.execFileSync (child_process.js:634:13)
at runOnAllDevices (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
-Concerning whether emulator is connected:
$ adb devices
List of devices attached
emulator-5554 device
(Works similarly for my Android smartphone). USB debugging is enabled.
-Concerning what I have tried to solve the problem:
My user is set as administrator.
I had JDK11.0.1 version. I installed JDK1.8.0_201 and it is now set as my java version.
User helloworld $ java -version
java version "1.8.0_201"
I created ".gradle" folder in my project's directory in case there are problems with accessing/creating this kind of folder.
-I specified the path for sdk.dir in local.properties file
-My OS is Windows 8.1. Gradle's version is 4.7.
-I have installed Android Studio, JDK8 and 11.
-I am using GitBash for the terminal purposes.
-I have the following system's environment variables:
ANDROID_HOME = c:\Users\User\AppData\Local\Android\Sdk
GRADLE_HOME = C:\Users\User.gradle\wrapper\dists\gradle-4.7-all\4cret0dgl5o3b21weaoncl7ys\gradle-4.7
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_201
Path = C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;.\Plugins;C:\Users\User\AppData\Local\Programs\Python\Python37-32;C:\Program Files\nodejs\;c:\Users\User\AppData\Local\Android\Sdk\platform-tools;C:\Users\User\AppData\Local\Android\Sdk\platform-tools;%GRADLE_HOME%\bin;%JAVA_HOME%\bin
In case you are interested what was in the question before:
My initial problem was that there just was not any error shown, but still nothing was launched on the emulator. I went around that by putting my project's "android" folder into Android Studio and it launched the app on my smartphone. However, when I introduced small changes to App.js, the project could not be updated due to some unknown error, and I couldn't reopen it as a new project. So I had to solve this problem by trying to run the app by using "react-native run-android" through terminal, and now I'm at this state of the problem.
Mmmm... when you run react-native run-android on the console, 1 it should check if you have the android sdk's, second it should compile some things, and third, it should start metro bundler in ANOTHER console . The "Loading dependency graph, done" should appear on that OTHER console, while the main console is gonna still compile for about a minute or even more... then it's gonna launch the intent and open the app. Sometimes it just displays a blank screen after the first load, so you should exit the app and delete it from recents, and reopen the app
Post screenshots, it seems like you only see that secondary console while the main console is not displaying (?)
Do you want to run a react-native or purely java application for which you must have used Android studio?
If for the studio app: you must enable the developer's options from your phone for enabling that check this:
https://www.samsung.com/uk/support/mobile-devices/how-do-i-turn-on-the-developer-options-menu-on-my-samsung-galaxy-device/

Categories

Resources