Building with Gradle - Supplied javaHome must be a valid directory - java

I am having a lot of trouble for what should be an easy task. I'm trying to build a simple Java project (just Hello World) with Gradle for one of my courses before classes begin. I cloned the repository, downloaded all the relevant software, and tried gradle build on the command line. I get the error Supplied javaHome must be a valid directory. You supplied: C:\Program Files\AdoptOpenJDK\jre-8.0.282.8-hotspot. This file that shows up was a previous version that I had removed.
I tried reinstalling everything, and I also checked the JAVA_HOME environment variable, which is set to C:\Program Files\AdoptOpenJDK\jdk-15.0.2.7-hotspot\. I've also relaunched the terminal and rebooted my computer. I'm using Git Bash as my shell, if that's anything relevant. Any advice on how to change the supplied javaHome?
Here are some relevant screenshots:
Result of gradle build
Result of java -version
JAVA_HOME environment variable
My (very sketchy) solution is to make a copy of the existing jre15 folder I have and rename it to jre-8.0.282.8-hotspot. I can build and run my program now, but it just seems very sketch.
One year update: I asked my prof when classes started when he said this solution was actually pretty ok and would suffice for the semester.

I had a similar problem building a Java app on GitHub Actions. Once I upgraded from Java 11 to Java 16 I started to get the same error as you.
In my case it turned out to be a caching problem. I was caching two directories:
~/.gradle (on windows this should be something like C:\Users\username\.gradle)
project/.gradle (this one is the gradle directory that is local to my app project).
Invalidating the caches fixed the issue for me.

I had a similar problem after uninstalling a Java version with Gradle deamon running. Stopping the deamon fixed the issue for me:
gradle --stop
(Probably, a cross-platform equivalent of Miguel's solution)

Update gradle(gradle-wrapper.properties) version from Android Studio to the lates version

For me i just deleted the .gradle in my folder C:\Users\username\.gradle.
With Android Studio, dependencies are automatically reinstalled

Related

Vs Code java The import cannot be resolved

I recently moved from windows 10 to Ubuntu 16.04, I'm a java developer, when I was on windows I installed Vs Code with the java Extension pack. On windows I never Had problem to make my daily work, but on ubuntu, every java file is marked as error, with the message "The import cannot be resolved", searching a litle bit, i found that you can execute the command java:clean the java language server workspace, but this does not fix the problem. I also remove the tmp files from the workspace located on:
~/.config/Code/User/workspaceStorage
the current Version of Vs code is 1.41.1
the current version of Java Extension Pack is 0.8.1
Any ideas?.
Regards!.
Edit:
all my java files are marked as error
inside of every java file
this is the result of the maven-install
well, after a while of searching, I found that the "maven for java" plugin was trying to download the maven plugin maven-metadata.xml, which wasn't available on my repo. this caused a conflict with the initial build that maven for java was doing. to avoid to update every time I opened vs code, I removed the option "update snapshots"
And the initial build was done.

Minecraft forge 1.14.4: missing library error (snapshot) in eclipse

I am trying to start modding Minecraft using Forge 1.14.4 but because of a "missing library" which is a snapshot, I will not be able to.
I have tried relentless online research but it never comes up.
In build.gradle, I noticed a part saying:
mappings channel: 'snapshot', version: '20190719-1.14.3'
The files being missing is preventing the project from being built.
The problem can be caused by having the wrong version of Java on your system path.
First, make sure you have the right JDK installed - jdk1.8.0_202 currently works for me. Download and install it if you haven't already.
Next, make sure it's the first version of Java in your path.
In Windows 10, press start, type 'Edit the system environment variables", and click Environment Variables.
Look for Path in the the System variables (the lower half of the screen, not the top half which may also have a Path variable).
There may be multiple lines that reference Java. On my computer I had two: C:\ProgramData\Oracle\Java\javapath and C:\Program Files\Java\jdk1.8.0_202\bin. I deleted the first reference.
Open a new console and run the gradlew commands from README.txt again
Some library is missing. Run the command gradlew eclipse after navigating into your project directory.
Is vecmath inside your build paths? I often had problems with it, but you can implement it manually.

Unable to start Gradle deamon in fresh install of Android Studio 0.8.1

I wanted to start some Android app development with my friend recently. I've installed the latest Android Studio 0.8.1 and cloned github repo. Then, when I try to build the project using Gradle, it is failing with the message:
Caused by: org.gradle.api.GradleException: 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/1.12/userguide/gradle_daemon.html
I am using Windows 8.1 64bit, JDK jdk1.7.0_60 64bit and gradle 1.12
I tried to:
- disable firewall and antivirus - didn't help
- download gradle manually, unzip and copy to .gradle in my home directory - didn't help
- when I open a blank new app I have same problem
- I moved the app to different directory as my user name contains 'ł' - same issue
Can anyone look at the log and try to help? This is the most annoying kind of issues developer can face - env is refusing to work and you can't code :(
<<< link to log >>>
Finally, after quite long fight last night, I have managed to run Android studio and build project with Gradle... and I hope it will stay so.
So, as #Eugen pointed out, this could be related to the fact that first installation of Android Studio was done for "only current user". Even I have uninstalled it and installed again it was still failing. Last night, I decided to uninstall it and also, manually, remove all remains of android stuff by simply deleting every directory with android, gradle etc. in its name ;)
I have also updated java to 7.65. and installed stand alone Gradle 2.0 and add it to PATH and check it is working.
After that, I done a clean install of android studio and open simple new MyApp project... and it works! Then I opened my other project - also working! I removed Gradle from PATH - still working.
I have no idea what was wrong... probably first installation of Android Studio was not completely correct. And unistalling it, didn't removed everything.
So, I have no clear answer for my issues, but I thought it could be helpful to describe the story. :)

Correct Java dependencies installed for eclipse ADT development

I have eclipse and the ADT bundle correctly installed on my home PC, and tried to install it on my laptop so I can work on my projects on the go. However, I either didn't set the java paths correctly, or installed them in the wrong place, because I can't get a default project to load without errors.
I have correctly:
-Installed the ADT bundle and launched eclipse without errors
-Created a workspace
-Correctly Installed both the jre8 and jdk1.8.0_05 in the location C:\Program Files\Java
I am very new to Android development, and I feel like I was lucky to set up the Java dependencies correctly on my home PC, no such luck this time from what the error look like...
However, when I try to make a basic "Hello world" project, I immediately get the following error:
The container 'Android Dependencies' references non existing library 'C:\Users\userName\workspace\appcompat_v7_3\bin\appcompat_v7_3.jar'
I have tried adding the library, by checking build configurations, but I don't understand fully whats going on to correctly solve the problem. Here is my workspace:
And lastly, I tried checking the build configurations to see that the libraries are, in fact, missing. Or something like that. I am not sure if I should just try to reinstall java and the jdk.
Build configuration:
Anyway, I'm not sure what I deleted, misplaced, uninstalled, or didn't install, but if anyone could point me to a solution I would be very grateful. If anyone has any other questions on my setup I will try and be as thorough as possible. Thank you!
In my experience I have had issues like this if not running eclipse as Administrator. Make sure that you aren't being blocked here.
EDIT: Please note Chris Stratton's concers regarding running an IDE as Administrator, as seen in the comments below.
EDIT 2: In my more recent experience, I have noticed that if I installed the SDK by copying and pasting the contents of the downloaded, compressed, folder to a destination rather than extracting it first, I would be required to run as Administrator. If this is the case, delete the SDK that you copied out of the compressed folder and simply extract the contents of the downloaded compressed folder. I am running Windows 7 so it is likely that this applies to all Windows 7 and 8 OS's.
In another case, I have also seen issues like this if the JRE is installed second rather than first. In this case, a reinstall of the SDK is probably all that is required.

R.java never appears

When I work on an android application in Eclipse, R.java never appears. I did the following to try to fix it:
delete ~/.eclipse folder
reinstall eclipse
create a new workspace
reinstall android developer tools
reinstall operating system
None of it worked. Even the Hello World! application that is created by default won't build. What do I have left I can do?
UPDATE:
There aren't any problems in Problems other than the two "R cannot be resolved to a variable"s. The Error Log tab shows an error Failed to load properties file for project from when I created the project. I think that may be a good clue as to what the root issue is.
ANOTHER UPDATE:
It's not a permissions issue, since the same thing happens when I run Eclipse as root. 'Fix Project Properties' does nothing. When I comment out the references to R.java, the problem is not resolved (the reason it doesn't run is [2013-07-08 21:47:37 - AppName] Could not find AppName.apk!
)
YET ANOTHER UPDATE:
running eclipse as root works now.
OS is 64-bit Arch Linux
Make sure that you have no xml related error( open and check all xml files, including the manifest manually).
Clean your project.
Change the build target version.
Make sure that you have Android SDK build tools. It comes on updating the ADT plugin.
Try these things:
Check in the properties of the project, in the Android tab if you have downloaded the version of the API that you are using. (See this in the SDK Manager)
Look into your /res folder. Scan for every file. Does any one has problems? If one resource has a problem, the R.java file is not generated.
Check the AndroidManifest.xml file. Look for warnings or problems, especially the use of the <uses-sdk> tag.
If none of these appointed the problem, try to build a simple java application. Does it work? Are you using the JDK 1.6?
Finally, if you are still stuck, download the Android ADT and use it as your IDE. It has all you need.
If your O/S is 64-bit Linux you will encounter Problems with the ADT because it is a 32-bit application. You have to install the following 32-bit libraries:
sudo apt-get install ia32-libs

Categories