Android Studio - supplied javaHome is not a valid folder - java

I decided to update my JDK to Java 8, and installed to the default location of C:\Program Files\Java\jdk1.8.0 with a jre subdirectory.
I wasn't sure how Android Studio worked out the JDK location, so I decided to launch it and see. I got the following message:
Failed to complete Gradle execution.
Cause:
Supplied javaHome is not a valid folder. You supplied: C:\Program Files\Java\jdk1.7.0_45
I updated my JAVA_HOME environment variable (both for system and user) to point to the new path, and tried adding it to my PATH variable as well, but every time I attempt to build in Android Studio I get the same message. The quoted path is nowhere to be found in my environment variables though, so where is it getting it from and how can I change it?
Thanks

The problem was my project's JDK location. From the Android Studio Project tool window, I right clicked on the root directory, selected 'module settings', and set the JDK location. Everything's fine now.

I don't know why or how this problem occurred but this answer got me over the hump. On macOS rm -rf ~/.gradle to wipe out the cache then restart Android Studio. I tried everything else up to and including reinstalling the JDK and Android Studio. Wiping out the .gradle directory is the only thing that worked.

Try to delete all .iml files and .idea, and re-import the project from Gradle. Worked for me (provided you have everything else set up).
This error happens when you switch from Intellij to Android Studio, or the other way around, and load the same project. Looks like their project model is not compatible.

For Android Studio 1.1.0, after right-clicking on the project:
Select Open Module Settings
Select SDK Location at top left
Type text into JDK Location: box

I ran into the same issue. My jdk was upgraded from a 1.8.0_172 to 1.8.0_202. And I kept getting the mentioned error although I changed to the right jdk, in the module configurations. What confused me was the fact that the API version was stamped with the old *_172 version in the dropdown of available project sdk's. I found the reason for this to be an old obsolete entry in the dropdown that referenced the old *172. After deleting this entry, the APi versions was magically stamped with the new version.
Note to self: Remember to sanitize your projects when new versions come along

I was also seeing this same problem. For me the fix was in 'Run/Debug Configurations' (Run > Edit Configurations...)
The 'Gradle project' value was set to the build.gradle file location, and this should've been set to the Gradle project object in IDEA, click the folder looking icon not the '...'.

I'm in 1.0.2 and after I clicked OK, it immediately opened a dialog to allow me to specify the location for my project, no longer requiring navigation of the menus to edit the project JDK path.
Definitely strange that during install, it says the JAVA_HOME environment variable is set to a path that doesn't contain the JDK. After spending time fixing it (downloading the full 64 bit JDK), I create my first project and get the same thing. Because it's not using the environment variable that it hinges on during setup.
Odd behavior.

For some reason I failed using all the above answers, so what I did is to delete (actually moved, so that I could go back in case something goes wrong) the ".idea" folder from the project. Then I opened the IDE again, and it went fine.

Getting this in 2021? Try to to rm -rf ~/.gradle and restart Android studio.

Related

Could not find builder.jar (com.android.tools.build:builder:3.1.0)

I wanted to Setting up android studio, i have installed the latest version(3.1.0) of it and i downloaded and installed the latest version of gradle(4.6) and created a new object. but gradle project sync failed. and shown up the error :
Could not find builder.jar (com.android.tools.build:builder:3.1.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.1.0/builder-3.1.0.jar
screenshot
I Couldn't find such problem with the others.
is it related to android sdk or gradle version?
is there any solution to download it manually and place it in the
location??if it's possible , where is the location ,that i can put the
builder-3.1.0.jar file.
Go to File>Setting>Build,Execution,Deployment>Gradle>Android Studio>>
and
Check mark this:: Enable Embedded repository
and Click Ok.
Then,
Rebuild the Project.
or
go to Terminal and type "gradlew cleanBuildCache" to clear the cache. The cache is in USERNAME.ANDROID\BUILD CACHE Directory.
And Rebuild.
Try deleting ~/.gradle folder and building the project again. Gradle will download that.
Accepted answer did not work for me, so I changed the class path line in gradle (project : project name) and issue is gone.
classpath 'com.android.tools.build:gradle:3.1.2'
I have tried all of the suggestions and none of them worked!
if you are facing the same issue i suggest you to do what solved my problem , i have found out the problem may caused because:
most likely at one time this dependency version was available, and so it’s now available on your Mac/PC in the filesystem (cache), and Gradle won’t try to download it (as it’s already downloaded). But then the version was removed / is no longer available, so it will no longer work on any new Mac/PC (as the dependency version can’t be downloaded).
hopefully if you have a backup before this problem happen these steps might help you to fix this issue
1) Backup or push the file you have changed to git (I suggest just your code files not anything related to gradles or android files)
2) delete C:\Users\ (your User)\ .gradle\caches
3) Do a clean git clone of the repository, into a new directory
4) Open new copy of your project with Android Studio and let Android studio sync gradles again
Check the version of Android Studio you are using...i was Android Studio 3.1 when it gave me the problem....i downgraded my Android Studio version to 3.0.1 and the problem solved.
I battled with the same problem for a very long time. But I was able to resolve it. You can try this:
Go FIle > Settings > Build, Execution, Deployment> Build Tools > Gradle then check the option Offline Work . You will notice that it points to a local gradle directory on your computer i.e C:Users/User_name/.gradle. Click Apply then OK. Run your project again, it should work.
Below is a screenshot:Screenshot of the Fix
go to SDK manager and download other SDK platform

The specified task executable location "C:\Program Files (x86)\Java\jdk1.7.0_71\\bin\javac.exe" is invalid

Ok im wondering where does xamarin get this path from?
Severity Code Description Project File Line Source Suppression State
Error The specified task executable location "C:\Program Files (x86)\Java\jdk1.7.0_71\\bin\javac.exe" is invalid.
So I can go and change it to the new jdk1.8. I have the new JDK set up I just need to know where to change the path at.
I had the same problem and solution is.
Remove all jdk and install jdk 1.8
Change reference java location in Visual Studio Tool > Options > Xamarin
Clean and Rebuild Project
I've just solved this exact problem for me.
I don't know why you wouldn't have a JDK_HOME variable. Completely remove the JDK and install it again maybe?
The Environment Variables for java were set to my previously installed path. I guess Oracle screwed up here.
As I had the same error, here's what I did:
I went to C:\Program Files\Java\ and checked what the jdk folder is called. For me it's jdk1.8.0_102.
For users who don't know where to find System Variables:
Go to System Properties and on the left hand side, click Advanced System Settings. Switch to the Advanced tab, click Environment Variables. Under System Variables there should be two variables in the list called JAVA_HOME and JDK_HOME.
I edited those values and change the path to what I found in the java folder. In my case this would be C:\Program Files\Java\jdk1.8.0_102.
No need to close VS, just build your app and it should get passed the annoying error.
Hope this helps :)
I had exactly the same problem. I got it to go away (which is not the same thing as fixing it).
Un-install every bit of JAVA you have. Delete both JAVA folders (Program Files and Program Files (x86)).
Install the latest version of the Java (x32) SDK.
Clean and Rebuild your project(s).
Since my Solution is multi-platform, I changed the Startup Project to the .iOS one, built it, ran it in an emulator, and set the Startup Project back to the .Droid project.
Somewhere in all this, the problem went away.
And remember kids! If it can go away all by itself, it can come back again all by itself!
I had this issue as well, I downloaded 32 bit Java but VS was still looking for the 64 bit one.
To solve it all I had to do was change the JAVA_HOME and the variable in my Path, clean my project and rebuild it.
Just set JAVA_HOME and JDK_HOME ambient variables, clean your solution and build again. For me worked fine.
Don't forget to clean your solution.

Android Gradle's dependency cache may be corrupt and gradle build not working

I am trying to import this project, even I tried to import other few projects too, I am getting below error.
https://github.com/ashdavies/data-binding
I have spent my 5 hours on it, even I tried many solutions on google but nothing gonna worked for me.
I tried following solutions, nothing worked.
1) delete .gradle directory
2) Restart IDE,
3) I tested with com.android.tools.build:gradle-experimental:0.7.0-alpha1
I am frustrated because of this Gradle and these issues.
Gradle Version : Gradle-2.13, I do not want to change this version.
Android Studio Version : Stable 2.1.1
Note : My other project is working fine and I can build it too.
You can try different workarounds for this problem :
1- Clean project and Rebuild it.
2- Before importing the project, remove the contents of the Build folders.
Then replace the contents of your gradle-wrapper.properties file with the following lines, to make it use a local distribution for building the project :
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=file\:/opt/gradle/gradle-2.13-all.zip
in which, the last line prevents android studio to download or use a corrupted gradle cache.
Go to any browser
type gradle and press enter
you can specify any version you want after the
gradle keyword
i am downloading gradle 3.3
https://services.gradle.org/distributions
click on this link which is in description directly if you want
click on gradle 3.3 all.zip
wait for the download to complete
once the download is complete
extract the file to the location
c://user/your pc name /.gradle/wrapper/dists
wait till extraction it takes 5 mins to complete
Now open your project in android studio
9.go to file > settings >bulid ,exec,deployment > gradle
now change use default gradle to
use local gradle distributn
select the location where you had extracted gradle 3.3.zip
C:\Users\your pc name.gradle\wrapper\dists\gradle-3.3
click on OK
Now build starts again and
you can see now the build is successful and error is resolved
or
watch tutorial
https://www.youtube.com/watch?v=u92_73vfA8M
In my case, it was happening because i haven’t set the JDK path in environment variable.
Please check from your Android studio studio that your JDK path is correct.
Go to Project Structure> SDK Location and check JDK Path. Give it the correct JDK path and also set the JAVA_HOME environment variable.
You can try this solution as i was facing this issue showing Error2 Gradle's dependency cache may be corrupt and gradle build not working and resolved it. Already answered this question on stack. You can reffer to this answer link
It includes firstly downloading latest graddle version from official site then replacing that unzipped file with home/yourUser/.graddle/wrapper/dists containg older version file on Mac.
Because your gradle path for project is incorrect.
Go to
->Settings
->Gradle
and select "use default gradle settings"
and than sync project. and issue will be resolved.
delete .gradle, .idea and gradle folder from the project and then invalidate cache and restart.
problem will be resolved.
Thanks :)
Sometimes it's a cache issue and sometimes due to interruption in download.
Step 1:
Try to download gradle distribution manually
https://services.gradle.org/distributions/
and then go to project settings -> gradle -> and use the file which you've downloaded
Step 2:
If step#1 still not working, then it may be a cache issue. If you are a mac user, go to your finder user folder, show hidden items by pressing [Command + Shift + .] , Go to gradle folder and
In my case is that gradle-5.1.1-all.zip download failed, so I go to zipStoreBase+zipStorePath(configured in gradle-wrapper.properties, eg: E:\gradle-home\wrapper\dists), and delete the gradle-5.1.1-all directory, and let android studio to download that zip file again.

Can't import the maven project in IntelliJ Idea 2016.1.1

I am trying to import a project in IntelliJ Idea 2016.1.1 using: File->Project from existing sources->choose the required pom.xml
It comes to this dialog box, but nothing happens on clicking next button.
I had the same issue, but managed to solve it by updating my /etc/hosts file such that there is was only one entry for localhost
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
# 192.xxx.xxx.xxx localhost <-comment out this
255.255.255.255 broadcasthost
#::1 localhost <- comment out this
In my case, this problem was solved by setting the JDK in IntelliJ IDEA settings. Like this:
Before selection correct JDK, I had the red text in this field.
I have had similar issue on my spare computer, the problem appears when creating/importing Maven project. It seems for some reason it has lost the access to java SDK and it was not there, even thus I tried to re-importing it. I tried to select java SDK again with out luck. I ended up with following solution:
Uninstalling IntelliJ (2016.2.4)
Reinstalling Java JDK latest 1.8, restart the system
Installing latest IntelliJ (2016.2.5)
First time I started IntelliJ, and when creating first time new project, ensure selecting the correct SDK path (see image)
Now you should be able to (click on next) creating/importing new Maven project.
The other answers did not helped me much.
I had the same issue just now,through the idea.log, I found the problem:
Caused by: com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java" (in directory "/Users/xxx/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/182.4129.33/IntelliJ IDEA.app/Contents/bin"): error=2, No such file or directory
at
com.intellij.execution.configurations.GeneralCommandLine.createProcess(GeneralCommandLine.java:408)
at com.intellij.execution.process.OSProcessHandler.startProcess(OSProcessHandler.java:51)
at com.intellij.execution.process.OSProcessHandler.<init>(OSProcessHandler.java:44)
at org.jetbrains.idea.maven.server.MavenServerManager$2.startProcess(MavenServerManager.java:367)
at org.jetbrains.idea.maven.server.MavenServerManager$2.execute(MavenServerManager.java:358)
at com.intellij.execution.rmi.RemoteProcessSupport.startProcess(RemoteProcessSupport.java:212)
at com.intellij.execution.rmi.RemoteProcessSupport.acquire(RemoteProcessSupport.java:139)
... 28 more
the jdk1.7.0_79.jdk have been removed,so it doesn't work...
I ran into this and at first it seemed due to the use of a tilde ~ in the file path of the root of the project. It also seemed to go "flaky" if you try to use a ~.
More investigation lead to:
/home/user/.IdeaIC15/system/log (might be a bit different for other systems)
Do
tail -100f idea.log
in a terminal in that directory and see what you get when you click "next"
Mine was missing / corrupt java7 instance
All this is pertaining to Linux only.
I had the same problem, turns out I had a lock on the directory. try renaming the folder to confirm this is not your issue. Once the lock is removed try importing the project.
I know this is older issue, but today I also encountered this issue. In my case it was JDK unavailable (as my IntelliJ was pointing to external JDK which got updated and old path didn't exists). Nevertheless, the issue can be different for different people. The best way to tackle this problem is to check intelliJ logs, that will tell you exact issue it is facing and then proceed with its fix. I'm sure this will save your time and you will solve the issue very quickly.
How to locate idea.log file is here
P.S. May be when you read this post, the above link to locate idea.log file stale. So kindly get the updated link from IntelliJ jetbrains website (Look for idea.log file path)
OR follow the below steps:
1. Open intellij
2. Click on Help tab from menu-bar
3. Select Show log in Finder. Get the path to this path and do tail -f </path-to-file/idea.log>
In my case to solve this problem I did a strace on Linux of the Intellij Java process that is called when you do a next (+ child processes) and discovered that it was related to the execution of the Maven embedded jar.
Execution of the Maven embedded jar (process 4940):
4940 execve("/home/rudy/Softwares/jdk1.8.0_111/bin/java", ["/home/rudy/Softwares/jdk1.8.0_11"..., "-Djava.awt.headless=true", "-Didea.version==2018.1.4", "-Xmx1024m", "-Didea.maven.embedder.version=3."...
Error returned by the process 4940:
4940 <... execve resumed> ) = -1 ENOENT (No such file or directory)
I had decided to move the jdk8 to a directory home/rudy/Softwares/jdks/jdk1.8.0_111 and it was previously in home/rudy/Softwares/jdk1.8.0_111.
It seems before to move JDKs used by Intellij to first reconfigure Intellij to use the new path and then use the import maven functionnality.
I did a mistake, it is true (moving the JDK) and Intellij has no way to know where the JDK was moved (unless scanning the all filesystem) but it should clearly display an error message and not get blocked on the 'next'.
I had this issue today and it took me 2 hours to identify and fix it.
I tried to import the project from perforce workspace which had '/' in the workspace name (ABC/lighting_workspace).
When I created another perforce workspace without '/' in the name (lighting_workspace), I was able to import the existing project :)
Had exactly the same issue, in my case it was a memory problem: the importer needed more memory than the one allowed by the VM's limit set by default after the installation of IntelliJ: I had 768 mb set by default and i moved them to 2048 mb.
You can set this under :
Preferences |-> Build, Execution, Deployment |-> Build Tools |-> Maven |-> Importing |-> VM options for importer
Install latest version of Intellij Idea (leave everything by default) and Java JDK (called SDK in IDE).
Create a new empty project.
Press Ctrl+Alt+Shift+F to open Project Structure panel.
Chose the SDK you downloaded, like : C:\Program Files\Java\jdk-10.0.2.
Apply and File->Open your project
Now it work ! (Also cleaned my host file)

Installed Android Studio 0.8.1 but can't get into IDE since no Android SDK

I installed (after unzipping) android-studio-ide-135.1224218-windows, hoping to be up and running a "hello world" program by now, but the IDE won't even start because "Your Android SDK is missing, out of date or missing templates." It tells me "You can configure your SDK via Configure | Project Defaults | Project Structure | SDKs" but when I do so, I see NOTHING in the text box for Android SDK location.
I searched for "android sdk" on my computer, and found C:\Program Files (x86)\Android\android-studio\plugins\android\lib\sdk-common.jar, but when I put that or C:\Program Files (x86)\Android\android-studio\plugins\android\lib into the text box, I get NO ERROR, but then I get the same message, and when I come back to the text box, IT DOESN'T HAVE WHAT I PUT INTO IT.
If I browse for the text box location, no matter what I put in, it says "Please choose a valid SDK directory".
That's the only "android sdk" on my computer.
I JUST installed Android Studio to C:\Program Files (x86)\Android\android-studio with no errors.
I have C:\Program Files\Java\jdk1.7.0_60 as JDK location. It won't let me change it to C:\Program Files (x86)\Java\jdk1.7.0_25.
I've Googled to see if I can download an android sdk from somewhere but found nothing.
WHAT DO I DO? I can't get into the IDE to try stuff.
sdk-common.jar is not the 'sdk' that Android Studio is looking for. You must download the sdk from SDK Manager and put it in the directory C:\Program Files (x86)\Android\android-studio\sdk.
This is what the sdk should contain:
sdk\build-tools
sdk\extras
sdk\platforms
sdk\platform-tools
...
I couldn't make use of the Answers above, so I uninstalled and then brute-force deleted EVERY trace of Android EVERYTHING.
Then I downloaded and installed installer_r23-windows.exe, putting the SDK manager out there BEFORE installing the Android Studio IDE. I allowed the default path: C:\Users\Dov\AppData\Local\Android\android-sdk.
Then I downloaded and installed android-studio-bundle-135.1245622-windows.exe--NOTE: BUNDLE, NOT IDE. I used the default folder: C:\Users\Dov\AppData\Local\Android\android-studio.
And I STILL got the SAME ERROR. But at least THIS time I could go into SDK Manager, as the error message said to do.
What I found was that the CORRECT path to the JDK, which was the same path shown in the SDK Manager dialog for installing packages. So why the error?
LOOOOOOONG story short... as I tried to browse for the path, I noticed that the AppData folder WAS NOT SHOWING.
SOLUTION: TYPE THE PATH BY HAND. It worked.
I CHANGED NOTHING, except my approach.
As it happens, "The [AppData] folder is hidden by default in File Explorer, and has three hidden sub-folders: Local, LocalLow, and Roaming." See here.
I assume that was Android Studio's problem, but why typing it by hand changed all that is anybody's guess.
I guess it's not a great idea to have AppData part of the DEFAULT install path.
(BTW, I did NOT have to mess with ANY environment variables.)
=== EDIT ===
I reinstalled Studio and SDK Manager and the above did not work. What I did BOTH times was to TRY to drag the SDK Manager.EXE file into the browse dialog from an Explorer window; it didn't work either time, but I tried today and THEN found success.... So I guess this seems to be a necessary step.... I also added \ after sdk in the text box for the SDK path.... And I clicked Apply before OK.... I hate when stuff works seemingly randomly.... Just trying to save others the frustration. Maybe Google needs to address this.
I had exactly this problem. After downloading Android Studio from the developer site:
android-studio-ide-135.1538390-windows.zip
But kept getting the error: "Your Android SDK is missing, out of date or missing templates."
Wasted several hours, but eventually went to the "Installing the Stand-alone SDK Tools" page:
https://developer.android.com/sdk/installing/index.html?pkg=tools
And downloaded and installed installer_r23.0.2-windows.exe.
Then I added its location to Configure -> Project Defaults -> Project Structure
I can now create projects.

Categories

Resources