简体   繁体   English

Gradle 包装器版本问题

[英]Gradle wrapper version issues

My task is to build an apk file using gradle wrapper via command line.我的任务是通过命令行使用 gradle 包装器构建一个apk文件。 I have a project in Android Studio 2.2.3 , it has a line in build.gradle file classpath 'com.android.tools.build:gradle:2.2.3' , which should mean, that it is using gradle version 2.2.3.我在 Android Studio 2.2.3有一个项目,它在 build.gradle 文件classpath 'com.android.tools.build:gradle:2.2.3'有一行,这应该意味着它使用的是 gradle 版本 2.2.3 . But when I call gradlew command from the project folder, there is always the same error: Unsupported major.minor version 52.0但是当我从项目文件夹中调用 gradlew 命令时,总是出现同样的错误: Unsupported major.minor version 52.0

I've used gradlew -v to recognize my gradle version, it is now 2.2.1 .我已经使用gradlew -v来识别我的 gradle 版本,它现在是2.2.1 Though when I manually change gradle version in build.gradle file from 2.2.3 to 2.2.1 I still get the same error.虽然当我手动将 build.gradle 文件中的 gradle 版本从2.2.3更改为2.2.1我仍然遇到相同的错误。

I checked the folder containing gradle on my computer.我检查了计算机上包含 gradle 的文件夹。 It has gradle version 2.14.1 .它有 gradle 版本2.14.1

I tried:我试过:

  • changing JDK path from 1.7 to 1.8 (JAVA_HOME variable)将 JDK 路径从 1.7 更改为 1.8(JAVA_HOME 变量)

  • manually changing JDK location at Project Structure -> SDK Location settings在项目结构 -> SDK 位置设置中手动更改 JDK 位置

  • in gradle settings: switching between using default gradle wrapper and local gradle distribution.在 gradle 设置中:在使用默认 gradle 包装器和本地 gradle 分发之间切换。

Interesting thing is that when I change gradle version in build.gradle to 1.5.0 the version error disappears, but I can no longer make any builds(it becomes unable to merge several jar files into one apk file)有趣的是,当我将 build.gradle 中的 gradle 版本更改为1.5.0 ,版本错误消失了,但我无法再进行任何构建(无法将多个jar文件合并为一个apk文件)

What is this version hell and how do I get rid of this error?这个版本是什么鬼,我该如何摆脱这个错误?

EDIT #1:编辑#1:

My /gradle/wrapper/gradle-wrapper.properties content is:我的/gradle/wrapper/gradle-wrapper.properties内容是:

#Fri Oct 21 12:53:56 EEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

EDIT #2:编辑#2:

I figured out that gradle versions are the same.我发现gradle版本是一样的。 So what JDK and JRE version should I use and how do I update them?那么我应该使用什么 JDK 和 JRE 版本以及如何更新它们? Simply downloading into Java folder and changing JDK location in Project Structure didn't help.简单地下载到 Java 文件夹并在项目结构中更改 JDK 位置并没有帮助。 在此处输入图片说明

EDIT #3:编辑#3:

My build.gradle file:我的 build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        flatDir {
            dirs 'libs'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:1.5.0-beta2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

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

My project-level build.gradle file:我的项目级 build.gradle 文件:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:design:23.4.0'
    compile "com.android.support:support-v4:23.4.0"
    compile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

SOLUTION:解决方案:

I needed to update targetSdkVersion and all dependencies to version 25 and set JAVA_HOME to jdk 1.8.我需要将 targetSdkVersion 和所有依赖项更新到版本 25,并将 JAVA_HOME 设置为 jdk 1.8。 Thanks, Abhishek Aryan谢谢,阿布舍克雅利安

Gradle version is different from Android Plugin for Gradle version. Gradle 版本不同于 Android Plugin for Gradle 版本。

This is Android Plugin for Gradle with version这是 Gradle 的 Android 插件版本

classpath 'com.android.tools.build:gradle:2.2.3'

And gradle with version和 gradle 版本

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM