Java 我的应用程序中不支持 Major.minor 版本 52.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35990995/
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
Unsupported major.minor version 52.0 in my app
提问by Rafael Reyes
I'm trying to compile my Android project and I'm getting this error
我正在尝试编译我的 Android 项目,但出现此错误
[INFO] Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
[INFO] at java.lang.ClassLoader.defineClass1(Native Method)
[INFO] at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
[INFO] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[INFO] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[INFO] at java.net.URLClassLoader.access0(URLClassLoader.java:71)
[INFO] at java.net.URLClassLoader.run(URLClassLoader.java:361)
[INFO] at java.net.URLClassLoader.run(URLClassLoader.java:355)
[INFO] at java.security.AccessController.doPrivileged(Native Method)
[INFO] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[INFO] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[INFO] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[INFO] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[INFO] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
I've been reading in other post that try to compile with Java 8 might cause that error but not my case, I have the following Java version:
我一直在阅读其他文章,尝试使用 Java 8 进行编译可能会导致该错误,但不是我的情况,我有以下 Java 版本:
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
OS: Linux Mint (I'm not have Java 8 installed.) Build: MAVEN
操作系统:Linux Mint(我没有安装 Java 8。)构建:MAVEN
Can anyone help me with this?
谁能帮我这个?
采纳答案by Rudy Kurniawan
I face this problem too when making new project from android studio.
从 android studio 制作新项目时,我也遇到了这个问题。
I've been able to resolve this by downgrading buildToolsVersion in app gradle setting: change {module-name}/build.gradle line
我已经能够通过在 app gradle 设置中降级 buildToolsVersion 来解决这个问题:更改 {module-name}/build.gradle 行
buildToolsVersion "24.0.0 rc1"
构建工具版本“24.0.0 rc1”
to
到
buildToolsVersion "23.0.3"
构建工具版本“23.0.3”
@Edit:
In Android Studio 2.1 Go to File-> Project Structure->App -> Build Tool Version. Change it to 23.0.3
@Edit:
在 Android Studio 2.1 中,转到文件-> 项目结构-> 应用程序 -> 构建工具版本。将其更改为 23.0.3
Do the method above, only when you are using java version 7 and for some reason do not want to upgrade to java 8 yet.
执行上述方法,仅当您使用的是 java 7 并且由于某种原因还不想升级到 java 8 时。
Hope this helps
希望这可以帮助
回答by cristianorbs
From thisquestion.
从这个问题。
You can try to change your compiler level back to 1.7 in the IDE you're using.
您可以尝试在您使用的 IDE 中将编译器级别更改回 1.7。
- If you're on Eclipse, go to Windows ---> Prefences then select Java and expand it then select Compiler and change the compliance level to 1.7.
If you're on Android Studio, you can add this to your build.gradle
android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 19 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } }
- 如果您使用 Eclipse,请转至 Windows ---> Prefences,然后选择 Java 并展开它,然后选择 Compiler 并将合规性级别更改为 1.7。
如果您使用的是 Android Studio,则可以将其添加到 build.gradle
android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 19 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } }
If this doesn't help, try checking other's answer in the link mentioned above and let us know what helped you.
如果这没有帮助,请尝试在上面提到的链接中检查其他人的答案,并告诉我们什么对您有帮助。
回答by Mike Playle
I just encountered this problem.
我刚遇到这个问题。
Reverting from the "Preview Channel" versions of the SDK tools and build tools to the latest stable version fixed it.
从“预览频道”版本的 SDK 工具和构建工具恢复到最新的稳定版本修复了它。
回答by coarist
I am on Android Studio 2.0 and facing the same problem. The solution provided by Rudy Kurniawan sorted out this issue. The affected file can be located by:
我在 Android Studio 2.0 上并面临同样的问题。Rudy Kurniawan 提供的解决方案解决了这个问题。可以通过以下方式找到受影响的文件:
"Project" -> "Android" -> "Gradle Scripts" -> "build.gradle(Module:app)"
“项目”->“Android”->“Gradle 脚本”->“build.gradle(Module:app)”
The "Project" pane is default on the left. To find it, inspect the name of the side tabs, click it, then use the top pull down box to get to "Android". Expand the tree in the pane to find the target file. Double-click it to edit.
“项目”窗格默认位于左侧。要找到它,请检查侧标签的名称,单击它,然后使用顶部的下拉框进入“ Android”。展开窗格中的树以查找目标文件。双击它进行编辑。
回答by Denis Kniazhev
Initially I had downgraded buildToolsVersion
from 24.0.0 rc3
to 23.0.3
, as specified in Rudy Kurniawan's answer. Then I have noticed that I have jdk 7 specified in my project settings. I have changed it to jdk 8 and now build tools 24.0.0 rc3
work.
最初我buildToolsVersion
已从降级24.0.0 rc3
到23.0.3
,如 Rudy Kurniawan 的回答中所述。然后我注意到我在我的项目设置中指定了 jdk 7。我已将其更改为 jdk 8,现在构建工具可以24.0.0 rc3
工作了。
It's also important to have compile options set to java7
:
将编译选项设置为java7
:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
回答by Gladys Sanchez
I had the same problem and tried to change the version, sometimes is for the version of Android Studio in Project> Gradle Scripts> build.gradle(Module:app) you can change the version. For example:
我遇到了同样的问题并尝试更改版本,有时对于项目> Gradle 脚本> build.gradle(Module:app) 中的 Android Studio 版本,您可以更改版本。例如:
android {
compileSdkVersion **23**
buildToolsVersion **"23.0.3"**
defaultConfig {
applicationId "com.example.android.myapplication"
minSdkVersion **19**
targetSdkVersion **23**
versionCode **1**
versionName **"1.0"**
}
回答by haithem
Thanks everyone for solution.
谢谢大家解决。
I could solve my same problem using below solution.
我可以使用以下解决方案解决我同样的问题。
In my project, I added jar which were created in Java8. And my project was referring to JRE 7. When i changed project JRE to 8. My problem solved.
在我的项目中,我添加了在 Java8 中创建的 jar。我的项目指的是 JRE 7。当我将项目 JRE 更改为 8 时。我的问题解决了。
Steps: In eclipse, right click on project name in project explorer > build path > Libraries > click on jre version > click edit > installed JRE > add > standerd VM > select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) > provide name > save > select same JRE for project > finish > ok Refresh/build project once > try to run your java file. it should work.
步骤:在eclipse中,在项目资源管理器中右键单击项目名称>构建路径>库>点击jre版本>点击编辑>已安装的JRE>添加>标准VM>选择JRE主页点击路径(路径应该是localePath\java\jdk1 .8.0_25\jre) > 提供名称 > 保存 > 为项目选择相同的 JRE > 完成 > ok 刷新/构建项目一次 > 尝试运行您的 java 文件。它应该工作。
回答by Habel Philip
Sorry for the late reply.Hope it helps someone else
抱歉回复晚了,希望能帮到别人
This problem is related with your SDK, not with your JDK. You can check your version information from
此问题与您的 SDK 相关,与您的 JDK 无关。您可以从
Help > About > Show Details
帮助 > 关于 > 显示详细信息
You will get something like
你会得到类似的东西
Xamarin.Android Version: 6.0.2.1 (Starter Edition) Android SDK: X:\Android\android-sdk
Supported Android versions:
4.0.3 (API level 15)
4.4 (API level 19)
6.0 (API level 23)
SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 24 rc2
Java SDK: X:\Program Files (x86)\Java\jdk1.7.0_71
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)
Xamarin.Android 版本:6.0.2.1(入门版)Android SDK:X:\Android\android-sdk
支持的安卓版本:
4.0.3(API 级别 15)
4.4(API 级别 19)
6.0(API 级别 23)
SDK 工具版本:24.4.1
SDK平台工具版本:23.0.1
SDK 构建工具版本:24 rc2
Java SDK:X:\Program Files (x86)\Java\jdk1.7.0_71
java版本“1.7.0_71”
Java(TM) SE 运行时环境(构建 1.7.0_71-b14)
Java HotSpot(TM) 客户端 VM(构建 24.71-b01,混合模式,共享)
If you are using preview tools for building ,then you will get similar errors all over.
如果您使用预览工具进行构建,那么您将到处遇到类似的错误。
What to do now?
现在做什么?
goto
去
Tools -> SDK manager
工具 -> SDK 管理器
Select all items in preview channels including
Android SDK build tools
with rev24rc2
or24rc4
(latest)Click on
Delete 'n' packages
选择预览频道中的所有项目,包括
Android SDK build tools
rev24rc2
或24rc4
(最新)点击
Delete 'n' packages
How to turn off preview channel
如何关闭预览通道
In SDK manager, select
Tools > options
Uncheck
Enable preview tools
在 SDK 管理器中,选择
工具 > 选项
取消选中
Enable preview tools
And what
还有什么
Back to your code Clean alland rebuild(In rare cases, you have to select build-tools from project settings page)
回到您的代码 Clean all并重建(在极少数情况下,您必须从项目设置页面中选择 build-tools)
回答by sotrh
I had the same problem with my IntelliJ Maven build. My "solution" was to go into the build tools and remove the build tools 24.0.0 folder. I found it in the {android-sdk-location}/build-tools/
directory. This is not a long term fix, but this should at least get your project building again. Upgrading to Java 8 as many have suggested will be better long term.
我的 IntelliJ Maven 构建也有同样的问题。我的“解决方案”是进入构建工具并删除构建工具 24.0.0 文件夹。我在{android-sdk-location}/build-tools/
目录中找到了它。这不是一个长期修复,但这至少应该让您的项目再次构建。正如许多人所建议的那样,升级到 Java 8 从长远来看会更好。
回答by Febrianto Nugroho
Gradle Scripts>> build.gradle (Module app)
Gradle 脚本>> build.gradle(模块应用程序)
Change buildToolsVersion "24.0.0"to buildToolsVersion "23.0.3"
将buildToolsVersion "24.0.0"更改为buildToolsVersion "23.0.3"
source : experience
来源:经验