使用Java 1.8 Gradle构建Android项目,即使Java Gradle工具链设置为JDK 11

Gradle building android project with Java 1.8 even though java gradle toolchain is set to jdk 11(使用Java 1.8 Gradle构建Android项目,即使Java Gradle工具链设置为JDK 11)
本文介绍了使用Java 1.8 Gradle构建Android项目,即使Java Gradle工具链设置为JDK 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FAILURE: Build failed with an exception.
* Where:
Build file '/bitrise/src/app/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.
Gradle检测本地安装的JVM Gradle选择与构建需求匹配的JRE/JDK(在本例中是支持Java 14的JVM) 如果没有找到匹配的JVM,它将自动从AdoptOpenJDK下载匹配的JDK

Android Gradle插件支持新的Gradle工具链吗? https://docs.gradle.org/current/userguide/toolchains.html

值得注意的库/插件/版本

  • 运行AGP 7.0.0-alpha03
  • Kotlin 1.4.21
  • Android Studio北极狐金丝雀3
  • jvmTarget 1.8
  • Gradle Wapper 6.8-RC-1

应用程序模块Gradle配置如下(删除了一些详细信息)

android {

    java {
        toolchain {
            languageVersion = JavaLanguageVersion.of(11)
        }
    }

    kotlinOptions {
        jvmTarget = Versions.jdkNumber
        useIR = true
    }

    buildToolsVersion Config.buildToolsVersion
    compileSdkVersion Config.compileSdk

    buildFeatures {
        compose true
        dataBinding true
    }

    composeOptions {
        kotlinCompilerVersion Versions.kotlin_version
        kotlinCompilerExtensionVersion Versions.compose
    }

    androidExtensions {
        experimental = true
    }
}

推荐答案

刚刚解决了这个问题,在项目根文件夹中添加了jitpack.yml文件,内容为:

jdk:
  - openjdk11
  • 帮助阅读:https://ayoubbenkhemis.medium.com/publish-android-library-with-jitpack-be00a29a8174

这篇关于使用Java 1.8 Gradle构建Android项目,即使Java Gradle工具链设置为JDK 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)