Android Studio shows an error when trying to use Embedded JDK instead of a custom install
Asked Answered
T

5

9

After I updated to Android Studio 2.3, I haven't been able to use the embedded JDK. When I try to build the project, I get errors like this:

Error:The newly created daemon process has a different context than expected.
Java home is different.
Expecting: 'D:\Development\IDE\AndroidStudio\jre' but was: 'C:\Program Files\Java\jre1.8.0_121'.
Please configure the JDK to match the expected one.
<a href="open.project.structure">Open JDK Settings</a>

But the JAVA_HOME environment variable isn't defined, but I can still use the normal JDK any problems, so I don't believe that's a problem. Where does Android Studio find the JAVA_HOME that prevents me from using the embedded JDK?

I tried uninstalled the system JDK to get it to work, and I updated java, which lead to it pointing to the JRE. I then reinstalled the JDK and when I point to it, it works fine. But I want to use the embedded JDK. Any ideas?

I have tried setting JAVA_HOME in gradle.properties, as linked in comments, but it still shows the error.

The line I added was:

org.gradle.java.home=D:/Development/IDE/AndroidStudio/jre

It should make the embedded JDK work (and change JAVA_HOME in the IDE) but it doesn't. It still leads to the same error mentioned at the top of this post.

In the snippet it says jre, and that was because when I copied it, I had just uninstalled the JDK. Updating the JDK and Java resulted in JAVA_HOME being set to the JDK location, but it isn't defined as an environment variable. I tried deleting the JDK table in Android Studio's config folder, but it did not work.

And what it looks when I set the JDK to be the embedded:

Screenshot showing the embedded JDK being enabled

Tingley answered 11/4, 2017 at 20:6 Comment(14)
related answer: https://mcmap.net/q/1182325/-gradle-in-android-studio-giving-error-project-sync-failedPinnati
I have tried that - still gives me the error(same as I posted in the question)Tingley
then you can see this - go to "Set the JDK version" section of the page.Pinnati
JDK version is not JDK locationTingley
there are instructions to use the bundled jdk there.Pinnati
Using u_111 of java (not JDK) and AS 2.2(.1?) I was able to use the embedded JDK by pressing the checkbox inside Android Studio. after updating to 2.3(and it still is an issue in 2.3.1) I get the error I posted in the question. Java_home isn't set officially on my computer, but setting it to the installed JDK doesn't give me the error. So do you know where Android Studio finds JAVA_HOME if it isn't from the environment variables?Tingley
I think I am out of ideas about this one here then. Whenever I search for jdk related similar issues and instructions, I am always getting ended up in somewhat same discussions and instructions. I am going to keep an eye on this question (already favorited) and see if someone else can find some other way.Pinnati
Why exactly do you want to use the embedded one? The snippet says jre because that is the folder that comes in Android Studio. Make an env variable, if you need oneVerbal
After using the embedded one, I came to find it uses less RAM, but does the same job. The jre is the folder in AS, yes but also the Java install(not JDK) on my computer. It expects the JDK to be at my Java(not JDK, just java) location.Tingley
Please post the result of the command echo %JAVA_HOME%in your Windows cmd.Deedeeann
Command: echo %JAVA_HOME% Prints: %JAVA_HOME% And as I mentioned, I haven't specifically set JAVA_HOME. Yet, Android Studio seems to set it on its own to my JDK install.Tingley
When you say "I have tried that - still gives me the error(same as I posted in the question)" in the @Pinnati comment above what exactly have you used in gradle.properties? Please post pictures. Also, consider the comment of Addilson in this https://mcmap.net/q/1318285/-failed-to-complete-gradle-execution-new-project-java-home-differentDeedeeann
Not build.gradle, gradle.properties. Picture coming.Tingley
Actually I was expecting a picture that could show which gradle.properties of your project you are using. Have you tried the Adilson's comment as I suggested? I tried this, but it just gave a different error. However, changing it to org.gradle.java.home=C:/Program Files/Java/jdk1.X.X worked. Note the forward slashes, and that I removed the jre at the end. – Addison Jan 15 at 10:20Deedeeann
G
3

Try to reset your path of your updated JDK. and check it again. May be it will help you. Also clear your android studio temp cache and all.

Gist answered 20/4, 2017 at 3:33 Comment(2)
"Reset your path" - JAVA_HOME or the JDK location in Android Studio? INvalidated caches/restart but it did not work.Tingley
install java where you installed your android studio.and then reset your java all path and check java from cmd and after that restart your system and check itGist
A
2

I fixed this issue by uninstalling all the jdk installation & updates then reinstall only one jdk and assure its env. variables

I do not have a solution but I have the same problem it happens as the android studio opens from java_home/jre thence all JVMs that will fork next will come from this path, while your system varible tells Gradle to get his java.exe from JAVA_HOME

I tried to make gradle read from jre but it falied also i tried to make android studio open from java_home/bin but it falid also

Airfield answered 19/4, 2017 at 7:14 Comment(1)
I did that, and t ostart with I only had two JDKs installed. Did not help. After removing the JDK and reinstalling the JRE, java home pointed to the JRE install. Then when I installed the JDK, it pointed to the JDK without me defining the JAVA_HOME. I never even defined JAVA_HOME, it just worked without itTingley
H
1

I had the exactly same issue with embedded JDK which was working on Android studio version 2.2.3 and when I updated then every time studio prompts JRE not found then I added system JDK path in project folder and now Whole Android studio hanging and I switched back to Android studio 2.2.3. It seems Android studio 2.3.1 is buggy release.

Hardpan answered 20/4, 2017 at 7:19 Comment(0)
F
0

It seems ,There are some miss match of JDK version.

So Try this: First Uninstall all Jdk/jre and Android Studio.

Clear temp/prefetch etc.

then Simply Install latest version of Android studio.

Remember: Don't install any other JDK/jre and make sure that your system have proper internet connectivity.All missing file automatically downloaded.

I had try this already and it was work for me .I hope it will also work for you.

Falla answered 21/4, 2017 at 6:17 Comment(1)
JDK and JRE are both the same version and I updated them when I started getting this issue. The issue happened after installing 2.3 and continued in 2.3.1. Currently running 2.3.1 which is the latest version. I invalidated/restart -> set embedded jdk(gave error) -> invalidate/restart -> still does not workTingley
H
0

I must say the AS has too many trouble in environment settings. There are some concepts we need to know.

  1. AS default java runtime environment itself ,as shown below.

AS default java runtime environment itself.

  1. System has another Java_home as shown below.

System's JDK version

Then problem is coming , what will happen when the system's JDK version doesn't match the AS's JDK version?

i.

java.lang.UnsupportedClassVersionError

ii.

gradle failure:certification ...

iii. There are some other error I couldn't remember now.

Solution: If your AS update to latest version,you should update your Gradle to latest version,and make sure your system's JDK is match AS's JDK version. At least, your idk version update to more than JDK1.8.0. When you do all of this ,try to restart your AS ,if does works ,try to restart your computer.

Extra: The proxy software has some influences when Gradle sync, if there are any tips about certificate ,try to close proxy software and try again.

Hocus answered 21/4, 2017 at 7:2 Comment(1)
Gradle and JDK is the latest update. Using 1.8 update 121Tingley

© 2022 - 2024 — McMap. All rights reserved.