尝试在 Android Studio 2.2.1 中运行新项目时出错
我刚刚更新到适用于 Mac 的 Android Studio 2.2.1.然后我将 JDK 更新到版本 8.尝试启动一个新项目并运行它.我收到以下错误:
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:
错误:(1, 1) 评估项目:app"时出现问题.
Error:(1, 1) A problem occurred evaluating project ':app'.
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : 不支持的major.minor版本52.0
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
我还尝试返回到 JDK 版本 7,因为它在 google 站点上说 JDK 8 对于 Mac 不稳定.还是出现同样的错误.
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.
检查您的 android 构建工具依赖项.在你的 build.gradle 中,如果它是这样的:
Check your android build tools dependencies. In your build.gradle if its something like:
classpath "com.android.tools.build:gradle:+"
它可能下载了 2.2 的 alpha,这可能会导致您看到的错误.
It has likely downloaded the alpha of 2.2 and that can cause the error you are seeing.
试试
classpath "com.android.tools.build:gradle:2.1.0"
如果您已经在使用正确的构建工具版本,但不断收到此错误,则可能是您使用的第三方 Android 库之一由于同样的原因导致了问题.您可以通过更改来强制使用依赖版本(包括可传递的)
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
classpath "com.android.tools.build:gradle:2.1.0"
到
classpath('com.android.tools.build:gradle:2.1.0') {
force = true
}
文档:gist 和 官方 gradle 文档.