Java 尝试在 Android Studio 2.2.1 中运行新项目时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37312404/
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
Getting error when trying to run new project in Android Studio 2.2.1
提问by IntangibleTech
I just updated to Android Studio 2.2.1 for Mac. Then I updated the JDK to version 8. Tried to start a new project and run it. I got the following error:
我刚刚更新到适用于 Mac 的 Android Studio 2.2.1。然后我将 JDK 更新到版本 8。尝试启动一个新项目并运行它。我收到以下错误:
Error:(1, 1) A problem occurred evaluating project ':app'.
错误:(1, 1) 评估项目“:app”时出现问题。
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : 不支持major.minor 版本52.0
I also tried going back to JDK version 7 as it says on google site that JDK 8 is unstable for Mac. still got the same error.
我还尝试回到 JDK 版本 7,因为它在谷歌网站上说 JDK 8 对于 Mac 不稳定。仍然有同样的错误。
回答by EricMorentin
Check your android build tools dependencies. In your build.gradle if its something like:
检查您的 android 构建工具依赖项。在你的 build.gradle 中,如果它是这样的:
classpath "com.android.tools.build:gradle:+"
It has likely downloaded the alpha of 2.2 and that can cause the error you are seeing.
它可能已经下载了 2.2 的 alpha,这可能会导致您看到的错误。
Try
尝试
classpath "com.android.tools.build:gradle:2.1.0"
If you are already using the right build tools version but keep getting this error, maybe one of the third party Android libraries you are using is causing the problem due to the same reason. You can force the dependency version to be used (including transitive) by changing
如果您已经在使用正确的构建工具版本,但不断收到此错误,则可能是您正在使用的第三方 Android 库之一由于同样的原因导致了问题。您可以通过更改来强制使用依赖项版本(包括可传递的)
classpath "com.android.tools.build:gradle:2.1.0"
to
到
classpath('com.android.tools.build:gradle:2.1.0') {
force = true
}
Documentation: gistand official gradle docs.
文档:要点和官方 gradle 文档。
回答by Kanak Sony
I was also facing the same problem. I upgraded Android Studio and as it forced to install JDK 8, downloaded and installed this as well. But we need to configure same in App Settings as well.
我也面临同样的问题。我升级了 Android Studio,因为它强制安装 JDK 8,所以也下载并安装了它。但是我们也需要在 App Settings 中进行配置。
- Select Project [Right click on the app module] -> Open Module Settings -> Select SDK Location from Left Menu - > Configured correct JDK Version i.e removed the old version and updated path of JDK. Save.
- Sync Project.
- 选择项目[右键单击应用模块] -> 打开模块设置 -> 从左侧菜单中选择 SDK 位置 -> 配置正确的 JDK 版本,即删除旧版本和更新的 JDK 路径。节省。
- 同步项目。
Problem solved!
问题解决了!
EDIT: Elaborated Project word.
编辑:详细的项目词。
回答by Smith John
I meet the problem too, but I have changed nothing before it's happening. I think google is purposely. Google is trying to use openJDK instead of JDK because of the lawsuit between google and oracle. So, in the new version 2.2.0 of android, we found that there are some new files in the installed folder:
我也遇到了这个问题,但在它发生之前我什么都没改变。我认为谷歌是故意的。由于谷歌和oracle之间的官司,谷歌试图使用openJDK而不是JDK。于是,在新的android 2.2.0版本中,我们发现安装文件夹中出现了一些新文件:
Then, I think we have two method to fix it:
然后,我认为我们有两种方法可以解决它:
Change the JDK environment variable of your OS.
Just click menu File --> Project Structure, choose Use embedded JDK (recommended). I chose this way and it work.
更改操作系统的 JDK 环境变量。
只需单击菜单 File --> Project Structure,选择Use Embedded JDK (recommended)。我选择了这种方式并且它有效。
Good luck...
祝你好运...
回答by Ashish Chaugule
回答by Usman lqbal
I had a same problem what is work for me is that .
我遇到了同样的问题,对我有用的是 .
Go *File>Settings>(on the panel left)Build,Execution,Deployment . then click on Gradle
转到 *File>Settings>(在左侧面板上)Build,Execution,Deployment 。然后点击Gradle
There is option to Update Gradle. Click on that it will time 3 to 4min and after that error gone.
有更新 Gradle 的选项。单击它会花费 3 到 4 分钟,然后该错误消失。
回答by Vadim Kotov
You can try to update JAVA_HOMEto point to JDK 8 location.
您可以尝试更新JAVA_HOME以指向 JDK 8 位置。
In my case, I've updated Android studio project's SDK settings, changed javaversion in my PATH env variable, but still this error occured. Only updating JAVA_HOME helped me.
就我而言,我已经更新了 Android Studio 项目的 SDK 设置,在我的 PATH 环境变量中更改了java版本,但仍然发生了此错误。只有更新 JAVA_HOME 对我有帮助。
回答by ViliusK
If you are on Jenkins, check Java version in Jenkins->Manage Jenkins->Global Tool Configuration->JDK
如果您在Jenkins 上,请在Jenkins->Manage Jenkins->Global Tool Configuration->JDK 中检查 Java 版本
I had to update mine to JDK 8.
我不得不将我的更新到 JDK 8。
回答by Alin Razvan
I had same error in 2.3 beta 1 ,
我在 2.3 beta 1 中遇到了同样的错误,
Fixed as follow :
固定如下:
Download latest java jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载最新的java jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
In Android Studio , go to File > Project Structure > SDK Location > select JDK Location path to point to the new jdk installed (Ex: C:\Program Files\Java\jdk1.8.0_111 )
在 Android Studio 中,转到 File > Project Structure > SDK Location > 选择 JDK Location path 指向安装的新 jdk(例如: C:\Program Files\Java\jdk1.8.0_111 )
Done !
完毕 !
回答by Srneczek
Ufff, I changed like everything I was able to find to jdk 8 and still no result but then I found Gradle settings in Intellij (preferences > gradle > GradleJVM) and it was ofc wrong, changed that and woala.
哎呀,我把我能找到的所有东西都改成了 jdk 8,但仍然没有结果,但后来我在 Intellij 中找到了 Gradle 设置(首选项 > gradle > GradleJVM),这是错误的,改变了它和 woala。
回答by superuser
The simplest way is to update Android Studio to v2.2.3, it includes a fix of JDK8:
最简单的方法是将 Android Studio 更新到 v2.2.3,它包括对 JDK8 的修复:
It's solved my problem.
它解决了我的问题。