Android Debug不支持major.minor版本52.0

时间:2017-10-13 18:07:10

标签: android android-studio-2.3

我导入了一个我工作了很多天的项目,但是我不得不升级Android Studio,然后,我收到了这个错误:

Error:(1, 1) A problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : 
Unsupported major.minor version 52.0

另外,当我检查我的课程时,我在每个R上都得到一条红线,并说无法解析符号R. 你知道怎么解决吗? 我的android Studio版本是:2.3.3

构建Gradle:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'

    // 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
}
apply plugin: 'com.android.application'

 android {
compileSdkVersion 23
buildToolsVersion '25.0.0'

defaultConfig {
    applicationId "hadirfinal.amjad.hadirfinal"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
 }

    android {
useLibrary 'org.apache.http.legacy'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.tools.build:gradle:2.1.3'
}

1 个答案:

答案 0 :(得分:0)

首先,检查您的Java版本。 Unsupported major.minor version 52.0与Java 8相关。从文件中检查SDK Location中的JDK - >项目结构 - > SDK位置:

enter image description here

然后使用build.gradle升级 root build:gradle:2.3.3

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
  }
}

allprojects {
  repositories {
    jcenter()
  }
}

task clean(type: Delete) {
   delete rootProject.buildDir
}

然后在应用 compileSdkVersion中使用相同版本更新buildToolsVersiontargetSdkVersionbuild.gradle和支持库。这里我们使用版本25.然后删除以下行compile 'com.android.tools.build:gradle:2.1.3',因为您不需要它。所以,它看起来像这样:

apply plugin: 'com.android.application'

android {
   compileSdkVersion 25
   buildToolsVersion '25.0.3'

  defaultConfig {
     applicationId "hadirfinal.amjad.hadirfinal"
     minSdkVersion 14
     targetSdkVersion 25
     versionCode 1
     versionName "1.0"
  }

  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

android {
   useLibrary 'org.apache.http.legacy'
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:25.3.1'
}