React Native: Error while running the android app - android

When running the android app in react native i'm geeting this error
Execution failed for task ':react-native-contacts:compileDebugJavaWithJavac'.
Could not find tools.jar. Please check that C:\Program Files\Java\New folder contains a valid JDK installation.
I have also checked the java version it is installted. My java version is 1.8.0_151.

add Jdk path org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144 to gradle.properties file and then run this command line in your projects root
cd android && gradlew clean && cd .. && react-native run-android

Related

react-native run-android ; SDK location no found, but it exists in the path

According to the react-native docs, I have installed Android 8.0 (Oreo) and the rest of the instructions. The only difference is that I have defined the path varibales in .bashrc and not .bash-profile. when I want to run my react-native application I face the Build failed with an exception.
the log looks like below:
sudo react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
the project built for me does not contain the local.properties. but I already have ANDROID_HOME in the Path.
$ printenv | grep Android
ANDROID_HOME=/home/amir/Android/Sdk
PATH=/home/amir/Android/Sdk/tools:/home/amir/Android/Sdk/tools/bin:/home/amir/Android/Sdk/platform-tools:/home/amir/Android/Sdk/emulator
As you mentioned local.properties not exist by default and you should add it to project.
Go to your React native Project -> Android
Create a file local.properties
Open the file
paste your Android SDK path like below
in Windows sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
in linux sdk.dir = /home/USERNAME/Android/Sdk
Replace USERNAME with your user name
Now, Run the react-native run-android in your terminal.

apk build file come with errors in react native android

Here, I have built the react native android app using this documentation Doc
in jenkins which was configured on ubuntu 16.04 (in virtual machine).
Here is the build command which I used to build the react native app(android) in Jenkins
cd $WORKSPACE && chmod -R 777 ./android && cd ./android && npm install && ./gradlew clean && ./gradlew assembleDebug
The build process end successfully creating an apk file in the following path
build_release_v1/ws/android/app/build/outputs/apk/
Note build_release_v1 is the jenkins project name and ws is for the workspace of it.
Though the apk is created it comes up with following errors
What may be the case ....please help me with this ...Thanks in advance...
The problem is that if you want a debug build (since you are using assembleDebug), React Native generates an APK that expects to have a connection to the bundle server (it does the same as react-native run-android). My guess is that you want to test the app without the bundler, so you have two options: either run assembleRelease instead (have a look here for more details) or manually create the bundled JavaScript code and then create the APK. Please refer to this question for details.

Failed to notify project evaluation listener > javax/xml/bind/annotation/XmlSchema

I trying to first run an react-native app with react-native run-android. I expect it to work, like it does when I call react-native run-ios.
Have a lot of users with same kind of error here on stack, "Failed to notify project evaluation listener".
Observed Behavior
> react-native run-android
Scanning folders for symlinks in /Users/tiagogouvea/www/go-along/mobile/node_modules (12ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod (file:/Users/tiagogouvea/.gradle/wrapper/dists/gradle-4.0-milestone-1-all/2rnr7rhi2zsmkxo9re7615fy6/gradle-4.0-milestone-1/lib/gradle-base-services-4.0.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /Users/tiagogouvea/Library/Android/sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> javax/xml/bind/annotation/XmlSchema
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 4s
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
Environment
npm ls react-native-scripts: empty
npm ls react-native: react-native#0.50.3
npm ls expo: empty
node -v: v8.0.0
npm -v: 5.5.1
yarn --version: 1.2.1
watchman version: 4.9.0
Operating system: macOs 10.12.6
Phone/emulator/simulator & version: Genymotion image
As mentioned in a comment to the bug filed by OP, Gradle seems to have issues with Java 9 or later.
You need to install JDK 8 (JRE is not enough, and versions later than 8 will not work) and tell Gradle to use it, not the default Java version on your system.
In my case (running Ubuntu 18.04), this required installing openjdk-8-jdk (I already had JDK 11 and JRE 8 but not JDK 8).
You have several ways of telling Gradle to use JDK 8 (in all examples, replace the path with the actual path to your JDK installation; the one shown here is valid for Ubuntu 18.04 amd64):
Run Gradle with the option
-Dorg.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
Ensure ~/.gradle/gradle.properties contains the line
org.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
In your build.gradle include the following lines:
compileJava.options.fork = true
compileJava.options.forkOptions.executable = /usr/lib/jvm/java-8-openjdk-amd64
That has helped me get rid of the same error on a different project.
In fact I was running Java 9, running a java --version gave me:
$: java --version
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
To solve it completely I did:
1) Removed Java 9:
sudo rm -rf "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
sudo rm -rf "/Library/PreferencePanes/JavaControlPanel.prefPane"
sudo rm -rf "~/Library/Application Support/Java"
2) Installed back Java 8 - download here
3) Added JAVA_HOME line to my bashfile (~/.bash_profile):
nano ~/.bash_profile
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
* Pay attention to use right jdk version on path
And, everything wokrs fine now. Thanks for help #user149408!
I've resolved this issue by cleaning all the Gradle cache, stoping the Gradle Daemon process, and created a new build successfully using the following command. Make sure your current directory is android.
rm -rf ~/.gradle/caches && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease

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