我的Android进阶之旅------>解决Android Studio报错:DefaultAndroidProject : Unsupported major.minor version 52.0

来源:互联网 发布:小孩曾卓君的淘宝店 编辑:程序博客网 时间:2024/06/06 03:44

今天使用Android Studio 2.1.1打开我之前的项目时,编译报了如下错误:

Error:Cause: com/android/build/gradle/internal/model/DefaultAndroidProject : Unsupported major.minor version 52.0
  • 1
  • 1

其中build.gradle文件内容如下所示:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:2.2.0-alpha4'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        jcenter()    }}task clean(type: Delete) {    delete rootProject.buildDir}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

这里写图片描述

如上所示,gradle的版本为2.2.0-alpha4。这是因为今天下了一个android Studio 2.2 Preview4,然后将该项目在Android Studio 2.2 Preview4中打开过,如下图所示:

这里写图片描述
这里写图片描述
因此gradle编译的版本就变成了2.2.0-alpha4。而且在Android Studio 2.2 Preview4中可以正常编译。

后来我又切换到了Android Studio 2.0,如下图所示: 
这里写图片描述
这里写图片描述
但是gradle版本还是2.2.0-alpha4,因此就出现了如题所示的错误:

Error:Cause: com/android/build/gradle/internal/model/DefaultAndroidProject : Unsupported major.minor version 52.0
  • 1
  • 1

解决办法

方法1

直接不用Android Studio 2.0了,转而使用Android Studio 2.2 Preview4编译该项目,继续开发。

方法2

在Android Studio 2.0中继续开发该项目,修改build.gradle文件内容,将gradle版本改成2.0.0,代码如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:2.0.0'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        jcenter()    }}task clean(type: Delete) {    delete rootProject.buildDir}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

然后再重新Sync Project With Gradle Files同步工程,如下所示: 
这里写图片描述
编译成功后的界面如下所示: 
这里写图片描述

至此,bug解决了!

阅读全文
0 0
原创粉丝点击