Android Studio - 无法确定 Java 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32796797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio - Could not determine Java version
提问by Zimad
I installed a fresh copy of Android Studio using terminal but when i create a new project it gives the error "Could not determine Java Version". JDK and SDK both are installed. Android Studio is updated to the latest version. I am using Ubuntu 14.04 LTS
我使用终端安装了一个全新的 Android Studio 副本,但是当我创建一个新项目时,它给出了错误“无法确定 Java 版本”。JDK 和 SDK 都已安装。Android Studio 已更新到最新版本。我正在使用 Ubuntu 14.04 LTS
采纳答案by Zimad
I simply changed default java JDK from Oracle JDK to OpenJDK. Works like a charm.
我只是将默认的 java JDK 从 Oracle JDK 更改为 OpenJDK。奇迹般有效。
回答by Filipe Batista
Did you set the JAVA_HOME environment? run echo $JAVA_HOME
in your terminal and see if you get a valid path to your Java binaries.
你设置JAVA_HOME环境了吗?echo $JAVA_HOME
在您的终端中运行,看看您是否获得了 Java 二进制文件的有效路径。
if not, set the the JAVA_HOME:
如果没有,请设置 JAVA_HOME:
nano .bashrc
Add the lines:
添加以下行:
export JAVA_HOME=<path to jdk>
export PATH=$JAVA_HOME/bin:$PATH
Save the file and then reload the .bashrc
保存文件,然后重新加载 .bashrc
source ~/.bashrc
回答by Nick Spacek
One potential problem is that older versions of Gradle can't parse the Java version from the java -version
output produced by the OpenJDK. Newer versions can (I think it was updated around Gradle 2.2; the latest, 2.9, works).
一个潜在的问题是,旧版本的 Gradle 无法从java -version
OpenJDK 生成的输出中解析 Java 版本。较新的版本可以(我认为它是围绕 Gradle 2.2 更新的;最新的 2.9 有效)。
回答by Anantha Raju C
I faced the same issue, but on windows 7 OS. It was because multiple versions of java was present in the same location C:\Program Files\Java
Java 5, 7, 8, and 9. Although the Environment variables JAVA_HOME and PATH were set to Java 8, Android studio was referring to Java 9.
我遇到了同样的问题,但在 Windows 7 操作系统上。这是因为C:\Program Files\Java
Java 5、7、8 和 9的同一位置存在多个版本的 Java 。尽管环境变量 JAVA_HOME 和 PATH 设置为 Java 8,但 Android Studio 指的是 Java 9。
My Solution, in the menu, click on File > Project Structure
here, point JDK to appropriate location C:\Program Files\Java\jdk
My Solution,在菜单中,点击File > Project Structure
这里,将JDK指向合适的位置C:\Program Files\Java\jdk
回答by user7007189
I faced the same issue, in ubuntu 16. It was because multiple versions of java was present in the same location 7, 8 and 9. Although the Environment variables JAVA_HOME and PATH were set to Java 8, Android studio was referring to Java 9.
我在 ubuntu 16 中遇到了同样的问题。这是因为在同一位置 7、8 和 9 中存在多个版本的 java。尽管环境变量 JAVA_HOME 和 PATH 设置为 Java 8,但 Android Studio 指的是 Java 9。
My Solution, in the menu, click on File > Project Structure here, select 8 version
My Solution,在菜单中,点击File > Project Structure here,选择8 version
回答by ked
change distributionUrl in gradle/wrapper/gradle-wrapper.properties to new version of gradle
将 gradle/wrapper/gradle-wrapper.properties 中的 distributionUrl 更改为新版本的 gradle
回答by Rob Johnny Tanen
Similar to Keds's answer. In android Studio, in Project Tab/File Explorer go to Gradle Scripts-> gradle.properties
类似于 Keds 的回答。在 android Studio 中,在项目选项卡/文件资源管理器中转到 Gradle Scripts-> gradle.properties
You will see something like this:
你会看到这样的事情:
#Sat Sep 21 13:08:26 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip
The distributionURL is old and, I'm assuming based on other answers, could not parse the Java version appropriately.
distributionURL 很旧,我假设基于其他答案,无法正确解析 Java 版本。
So picked a newer version by going to this site: http://services.gradle.org/distributions/
所以通过访问这个站点选择了一个更新的版本:http: //services.gradle.org/distributions/
I picked
我选了
distributionUrl=http\://services.gradle.org/distributions/gradle-4.8.1-all.zip
just because. There are newer versions, such as 4.10.2, but I'm not really using gradle, it's just required for the project.
只是因为。有更新的版本,例如 4.10.2,但我并没有真正使用 gradle,它只是项目所必需的。
Also, although it didn't really affect me running my project, my project wasn't pointing to the new JDK. It was pointing to Android Studio's jre file automatically as recommended.
此外,虽然它并没有真正影响我运行我的项目,但我的项目并没有指向新的 JDK。它按照建议自动指向 Android Studio 的 jre 文件。
If you want to change this, get the file path location of the newest Java JDK. Usually in
如果要更改此设置,请获取最新 Java JDK 的文件路径位置。通常在
C:\Program Files\Java\your_jdk_file
for windows. In Android Studio, go to File -> Project Structure -> SDK Location.
用于窗户。在 Android Studio 中,转到文件 -> 项目结构 -> SDK 位置。
Uncheck 'Embedded JDK (recommended)', then paste the file path to the newest JDK file path for the entire file.
取消选中“嵌入式 JDK(推荐)”,然后将文件路径粘贴到整个文件的最新 JDK 文件路径。
Such as
如
C:\Program Files\Java\jdk-10.0.2
And not just the bin file. Good luck!
而不仅仅是bin文件。祝你好运!
回答by Vick Tim
Nothing of this worked for me so in case it can help someone else : Right click on "app" in your project, go to "Open Module Settings">"Properties" and change the source compatibility and target compatibility to the Java version you need.
这对我没有任何帮助,以防万一它可以帮助其他人:右键单击项目中的“应用程序”,转到“打开模块设置”>“属性”并将源兼容性和目标兼容性更改为您需要的 Java 版本.
回答by no_cola
Change this:
改变这个:
targetCompatibility 'JavaVersion.VERSION_1_8'
sourceCompatibility 'JavaVersion.VERSION_1_8'
to this:
对此:
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
回答by Islam Assem
well ,what solved the problem for me is that i didn't use embeded jdk and then set java version to java 7 and build it gave me error because of lambda expression then i set java version to 1.8 and sync then build and it worked
好吧,对我来说解决问题的是我没有使用嵌入式 jdk 然后将 java 版本设置为 java 7 并构建它因为 lambda 表达式给了我错误然后我将 java 版本设置为 1.8 然后同步然后构建并且它工作