android gradle build in command line error: Unsupp

2019-09-19 11:02发布

Build inside android studio works, but failed with command line build

> gradlew tasks

java.lang.UnsupportedClassVersionError: 
com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.android"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

The line apply plugin: 'com.android.application' causes the error. where does the major.minor version 52.0 come from?

2条回答
欢心
2楼-- · 2019-09-19 11:22

make sure gradle plugins are latest:

classpath 'com.android.tools.build:gradle:2.3.3'
查看更多
forever°为你锁心
3楼-- · 2019-09-19 11:28

Fix your JAVA_HOME variable.

The error means there are classes compiled with Java 8 (52.0) that you are trying to use with an older Java version.

When you use Android Studio obviously Java 8 is used to run Gradle, but when you use the Gradle wrapper from commandline, the value of JAVA_HOME is used to execute Gradle.

This is set to Java 7 or older on your machine and thus the build fails as soon as it tries to use the Java class that was compiled with Java 8, in your case a part of the Android Gradle plugin.

查看更多
登录 后发表回答