android - 无法应用插件 'com.android.internal.application' Android Gradle 插件需要 Java 11 才能运行。您当前使用的是 Java 1.8

标签 android maven gradle jitpack

我想在 jitpack 中发布一个简单的库。我创建了一个 Android 项目并添加了新的 Android 库模块并将项目推送到 github。像这样编辑 build.gradle 库模块
enter image description here
并添加 maven { url 'https://jitpack.io' }根 build.gradle
但我得到错误。日志是:

Build starting...
Start: Sun Aug 22 05:14:22 UTC 2021 d352f549d622
Git:
1.0.0-0-g9e976ac
commit 9e976acd32d4b2d1b3b645779f2b72b1450c9f0e
Author: alireza 
Date:   Sun Aug 22 09:40:19 2021 +0430

    Initial commit


Found Android manifest
Android SDK version: . Build tools: 
Found gradle
Gradle build script
Found gradle version: 7.0.2.
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Downloading https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
.10%.20%.30%.40%.50%.60%.70%.80%.90%.100%

------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_252 (Private Build 25.252-b09)
OS:           Linux 3.16.0-10-amd64 amd64

0m5.588s
Getting tasks: ./gradlew tasks --all
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jitpack/build/app/build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> 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`.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 33s
Tasks: 

WARNING:
Gradle 'install' task not found. Please add the 'maven' or 'android-maven' plugin.
See the documentation and examples: https://jitpack.io/docs/

Adding maven plugin
Found android library build file in mytoastlibrary
Running: ./gradlew clean -Pgroup=com.github.shojaeialireza -Pversion=1.0.0 install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

> Configure project :
Gradle version Gradle 7.0.2

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jitpack/build/app/build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> 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`.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
2021-08-22T05:15:11.863645465Z
Exit code: 0

ERROR: No build artifacts found
JDK 版本在 android studio 设置中为 11。
我该如何解决这个问题?

最佳答案

我遇到了同样的问题,我通过以下方式修复了它:

  • 我将系统中的 java 更新为 JAVA 11 ,更新了设置首选项中的 build.gradle 和 Gradle。

  • 编译选项 {
    sourceCompatibility JavaVersion.VERSION_11
    目标兼容性 JavaVersion.VERSION_11
    }
    kotlinOptions {
    jvmTarget = '11' }
    enter image description here
  • 创建 jitpack.yml项目根文件夹中的文件
    JDK:
  • 打开jdk11
    安装前:
  • ./scripts/prepareJitpackEnvironment.sh


  • enter image description here

    关于android - 无法应用插件 'com.android.internal.application' Android Gradle 插件需要 Java 11 才能运行。您当前使用的是 Java 1.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68878785/

    相关文章:

    java - Gradle 项目 - 可以构建但不能运行它

    android - 在 ListView 中放置图像边框的方法

    java - 在 Android 上对共享库进行数字签名

    android - 如何将我的应用程序的所有声音静音?

    android - react native :-How to use a common drawer and toolbar across all pages with control

    java - 从 3.0.0 升级后无法运行 Gxt 3.1.1 应用程序

    android - Flutter:尝试向 FlutterEngine 自动注册插件,但找不到并调用 GeneratedPluginRegistrant

    java - Gradle 不会复制测试资源来构建

    maven - 安装具有 3rd-party non-mvn jar 依赖项的 3rd-party non-mvn jar

    java - Java JDK10 中的 TypeTags 错误