Gradle project sync failed in android studio in linux - java

I use android studio in linux os. When I create a project or open a new project, I found the following error:
Error: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 guide chapter on the daemon at http://gradle.org/docs/2.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
22:25:20.715 [main] DEBUG o.g.l.daemon.bootstrap.DaemonMain - Assuming the daemon was started with following jvm opts: [-XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx512M, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant]
FAILURE: Build failed with an exception.
What went wrong:
Could not create service of type DaemonContext using DaemonServices.createDaemonContext().
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
how to resolve this problem in linux os on my android studio?

I had this problem in Ubuntu 14.04 where /tmp was mounted with noexec parameter. To fix this I needed to remount with exec allowed:
mount -o remount,exec /tmp
The issue is referenced here:
https://discuss.gradle.org/t/gradle-v1-12-daemon-fails-to-start-if-tmp-is-mounted-with-noexec/2077

Related

Unrecognized VM option 'MaxPermSize=512m' and Could not create the Java Virtual Machine when running React Native Apps (closed)

I tried to run react native app with this command.
npx react-native run-android --variant=stagingDebug --appId com.xx_staging
But I am getting this error message. I want to run multiple java versions on my machine. How can I do that? Also I don't want to change the MaxPermSize=512m. I want to keep MaxPermSize=512m as it is.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 2228 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
'"adb"' 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...
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/6.7/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-18.0.2.1\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\rbza9\.gradle\wrapper\dists\gradle-6.7-all\cuy9mc7upwgwgeb72wkcrupxe\gradle-6.7\lib\gradle-launcher-6.7.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* 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
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:installStagingDebug -PreactNativeDevServerPort=8081
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/6.7/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-18.0.2.1\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\rbza9\.gradle\wrapper\dists\gradle-6.7-all\cuy9mc7upwgwgeb72wkcrupxe\gradle-6.7\lib\gradle-launcher-6.7.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* 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
at makeError (F:\test\xx\node_modules\execa\index.js:174:9)
at F:\test\xx\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (F:\test\xx\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (F:\test\xx\node_modules\#react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
How can I fix this error?
This option was completely removed between Java 11 and Java 17. If you want to use Java 17 or later you must remove MaxPermSize=512m - the JVM will plainly refuse to start if that option is present .
Please note that already with Java 8 this option no longer had any effect and can therefore be safely removed even for Java 8. (https://docs.oracle.com/javase/9/migrate/)
The only possible reason to keep this option in some configurations is if you still must support Java 7. But Java 7 is so much outdated that IMHO it is questionable if any time spent supporting Java 7 is time well spent.
The option seems to be decommissioned.
You can add to the command line which starts your app a flag -XX:+IgnoreUnrecognizedVMOptions. In this case, JVM will ignore all unrecognized flags.

How can I solve Build Failed problem with React Native?

I am new to React Native and I recently build a simple application and I want to release it but I get the following error (I had followed every step mentioned in the blog by react native)
The Problem I encountered while running gradlew assembleRelease is FAILURE: Build failed with an exception
Output
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
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/6.9/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-18\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\Lucifer\.gradle\wrapper\dists\gradle-6.9-all\dooywd8nv05k16orzxge2b1bs\gradle-6.9\lib\gradle-launcher-6.9.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.9
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* 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
I don't know if it is the problem with JDK
I have properly installed JDK (Version 18) and added the path to SDK in the environment variable
ANDROID_HOME = C:\Users\Username\AppData\Local\Android\Sdk
and I also have added the path to java/jdk-18/bin folder and platform-tools in environment paths variable
I tried some of the solutions from previous issues regarding this problem like this one but none of them worked.
I tried reading documentation and GitHub issues but couldn't find relevant solution
so
How exactly do I solve this problem?

Unable to start the daemon process. how can I solve it please

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/6.5/userguide/gradle_daemon.html
Process command line: C:\Program Files\Android\Android Studio1\jre\bin\java.exe -Xmx2048m -Dfile.encoding=UTF-8# -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\Acer.gradle\wrapper\dists\gradle-6.5-bin\6nifqtx7604sqp1q6g8wikw7p\gradle-6.5\lib\gradle-launcher-6.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.5
Please read the following process output to find out more:
Check the JVM arguments defined for the gradle process in:
gradle.properties in project root directory
i tried to change "org.gradle.jvmargs=-Xmx2048m" to "org.gradle.jvmargs=-Xmx1024m"
and deleted file gradle
nothing worked
you can go to gradle.properties
go to file version and gradle properties, open it and change with this org.gradle.jvmargs=-Xmx1024m next you can sync the gradle and ready to build run.

react native java.lang.ExceptionInInitializerError

I'm trying to make React Native work on an emulator. I'm using Genymotion it works fine, the virtual machines opens without any problem and i have added the SDK to its configuration.
I have the emulator opened and working but when i run react-native run-android i get the following error.
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
java.lang.ExceptionInInitializerError (no error message)
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
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
I've found out that a possible problem is that i was runnig java 9 and React Native requires java 8 instead (https://github.com/facebook/react-native/issues/11755)
So i did the following
I tried changing the version by doing this
sudo update-java-alternatives --set java-8-oracle
then checking the version with
javac -version
it returns javac 1.8.0_131
If i run the app again i still get the error from above
But when i echo $PATH i see that it is still referencing the java 9 folder
echo $PATH /home/andrei/.nvm/versions/node/v7.5.0/bin:/home/andrei/bin:/home/andrei/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/home/andrei/Android/Sdk
How do I change that or fix this problem?
To fix this problem
But when i echo $PATH i see that it is still referencing the java 9 folder
echo $PATH /home/andrei/.nvm/versions/node/v7.5.0/bin:/home/andrei/bin:/home/andrei/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/home/andrei/Android/Sdk
in The Home directory open .profile
add the following
PATH="$PATH:~/usr/lib/jvm/java-8-openjdk-amd64/bin"
in this case i'm adding the path to java 8 folder because that is the one i need to use The React-Native according it its specification
https://facebook.github.io/react-native/docs/getting-started.html
after setting the PATH you need to make it available inside the terminal you are executing the react-native app by using the following script
source .~/.profile
this should get you passed the initial problem with the java 9

Gradle ignores daemon ignore flag

I'm running Gradle 3.2.1 on MacOS X 10.12.1 installed with brew install gradle, did not set any env variables etc. myself, trying to use the Java 9 EA:
gradle build -Dorg.gradle.java.home=~/jdk-9.jdk/Contents/Home
But the build is failing with
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.
From what I know it fails because the daemon is trying to use the maxpermsize JVM option (which is not supported in Java 8+ but in Java 8 it's only a warning).
So I tried to disable the daemon:
mkdir -p ~/.gradle && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties
But gradle build is still trying to start a daemon... I removed ~/.gradle and .gradle in the project directory. Any other ideas?
$ gradle build -Dorg.gradle.daemon=false -Dorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.2.1/userguide/gradle_daemon.html.
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 guide chapter on the daemon at https://docs.gradle.org/3.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
> Starting Daemon%
Ok so I figured it out, since I'm running my build like this:
gradle build -Dorg.gradle.java.home=~/jdk-9.jdk/Contents/Home
Gradle has to spawn a new thread to use a different Java version than the one pointed to by JAVA_HOME. This is done by spawning a daemon thread (even despite the false option) with that Java version and is failing. The same would happen if I passed JVM args to the build apparently.
The solution is to instead set JAVA_HOME in the terminal export JAVA_HOME=~/jdk-9.jdk/Contents/Home and just run gradle build.
Still doesn't work because the newest Java9 build broke Gradle's reflection but that's a different story.
I am posting this here since it's too big of a comment (but it is for sure not an answer).
If you run your script with --debug you will see the underlying error. I am running this directly via java-9 without setting the JAVA_HOME btw.
I had the same issue a few jdk-9 builds back and tackled it with:
set _JAVA_OPTIONS "-Dsun.reflect.debugModuleAccessChecks=true
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent=ALL-UNNAMED
--add-opens=java.base/java.text=ALL-UNNAMED"
set instead of export because I'm using fish, but should work for bash the same way.
Interestingly enough this still fails with build 153 with this:
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module #67080771
But that is specified within _JAVA_OPTIONS. This might be a regression on build 153.

Categories