未能应用插件“com.android.internal.library”。 Android Gradle 插件需要 Java 11 才能运行。您当前使用的是 Java 1.8

Posted

技术标签:

【中文标题】未能应用插件“com.android.internal.library”。 Android Gradle 插件需要 Java 11 才能运行。您当前使用的是 Java 1.8【英文标题】:Failed to apply plugin 'com.android.internal.library'. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8 【发布时间】:2021-07-21 14:49:25 【问题描述】:

我想使用 Jetpack Compose 构建一个库并使用 jitpack.io 发布它。 我使用的是金丝雀版本的 android studio android studio canary version。 我已经构建了项目,将其推送到 Github,发布了然后我将我的 repo 的链接放在 jitpack.io 中以生成 lib 依赖链接“implementation 'com.github.user:compose-lib:Tag' " 但是出了点问题,我从 jitpack 收到了这个日志错误:

Build starting...
Start: Tue Apr 27 14:25:17 UTC 2021 0c5235afbe25
Git:
0.9.0-0-g13dbaf9
commit 13dbaf941d2c59d8e70ed64b868488abb7f3f2e1
Author: username 
Date:   Tue Apr 27 14:29:45 2021 +0200

    gradle plugin require Java 11 to run


Found Android manifest
Android SDK version: . Build tools: 30.0.3
Installing Build-tools 30.0.3 
Found gradle
Gradle build script
Found gradle version: 7.0.
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-rc-1-bin.zip
.
Unzipping /home/jitpack/.gradle/wrapper/dists/gradle-7.0-rc-1-bin/14lahl8r8vkgd4j5n81i3rsld/gradle-7.0-rc-1-bin.zip to /home/jitpack/.gradle/wrapper/dists/gradle-7.0-rc-1-bin/14lahl8r8vkgd4j5n81i3rsld
Set executable permissions for: /home/jitpack/.gradle/wrapper/dists/gradle-7.0-rc-1-bin/14lahl8r8vkgd4j5n81i3rsld/gradle-7.0-rc-1/bin/gradle

Welcome to Gradle 7.0-rc-1!

Here are the highlights of this release:
 - File system watching enabled by default
 - Support for running with and building Java 16 projects
 - Native support for Apple Silicon processors
 - Dependency catalog feature preview

For more details see https://docs.gradle.org/7.0-rc-1/release-notes.html


------------------------------------------------------------
Gradle 7.0-rc-1
------------------------------------------------------------

Build time:   2021-03-23 01:02:30 UTC
Revision:     f5bf7ade373b74058e49f07749083b4c3075549a

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 4.14.63-xxxx-std-ipv6-64 amd64

0m3.102s
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/mylib/build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > 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 24s
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 mylib
Running: ./gradlew clean -Pgroup=com.github.user -Pversion=0.9.0 install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

> Configure project :
Gradle version Gradle 7.0-rc-1

FAILURE: Build failed with an exception.

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

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > 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-rc-1/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-04-27T14:25:58.25891409Z
Exit code: 0

ERROR: No build artifacts found

这里是我的库的 build.gradle 文件:

plugins 
    id 'com.android.library'
    id 'kotlin-android'


android 
    compileSdk 30
    buildToolsVersion "30.0.3"

    defaultConfig 
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    

    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    
    kotlinOptions 
        jvmTarget = '11'
    

    buildFeatures 
        compose true
    

    composeOptions 
        kotlinCompilerVersion "1.4.32"
        kotlinCompilerExtensionVersion "1.0.0-beta05"
    


java 
    toolchain 
        languageVersion.set(JavaLanguageVersion.of(11))
    


tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach 
    kotlinOptions 
        jvmTarget = "11"
    


dependencies 

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"

我把java版本从1.8改成了11还是不行。

这里是我的 android studio 配置:Gradle JDK

文件>项目结构>SDK位置:SDK Location

任何帮助将不胜感激!

[EDIT]问题解决通过配置Jitpack在Java 11上运行。我添加了jitpack.yml文件,其中包含

jdk:
  - openjdk11

您可以参考这个article了解更多详情。

【问题讨论】:

【参考方案1】:

JDK 的路径是否正确?您可以检查文件 > 项目结构 > sdk 位置。 请验证此位置是否基于 jdk 11。

【讨论】:

我在文件 > 项目结构 > sdk 位置中没有看到任何 JDK,我只有 Android SDK 位置和 Android NDK 位置。我用一张图片更新了我的问题,你可以看到它。 你是从Java官网下载安装JDK 11并设置全局路径的吗? 是的,我在调用 java --version 时有这个输出:openjdk 11.0.11 2021-04-20 LTS OpenJDK Runtime Environment Corretto-11.0.11.9.1 (build 11.0.11+9-LTS ) OpenJDK 64-Bit Server VM Corretto-11.0.11.9.1(build 11.0.11+9-LTS,混合模式) 如果您已正确设置工作室的 JDK 路径,请通过此链接进行验证:developer.android.com/studio/intro/studio-config

以上是关于未能应用插件“com.android.internal.library”。 Android Gradle 插件需要 Java 11 才能运行。您当前使用的是 Java 1.8的主要内容,如果未能解决你的问题,请参考以下文章

解决了jQuery插件未能导入到项目之中

您好,我的VS2010提示没有安装或未能初始化关联的源代码管理插件,怎么解决的!挺急的,谢谢了!!

使用 createDrawerNavigator() 时出现“错误:Reanimated 2 未能创建工作集,可能你忘记添加 Reanimated 的 babel 插件”

未能执行数据表搜索

未能找到与此解决方案关联的源代码管理提供程序

运行在Wayland的Qt应用程序