如何将 Android 项目升级到 Java 11 [英] How to upgrade an Android project to Java 11
问题描述
我正在使用最新的 Android Studio Arctic Fox 2020.03.01 Canary 8 和 AGP 7,并且我想将我的项目转换为使用 Java 11.显然,仅执行以下操作并不能像
之前
我假设您安装了 Java 11 或更高版本.以下步骤:
文件 ->项目结构 ->SDK 位置 ->将 JDK 位置更改为 Java 11 jdk 文件夹
如果您使用的是 Mac OS,请尝试在以下位置搜索该文件夹:
/Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home
I am using the latest Android Studio Arctic Fox 2020.03.01 Canary 8 and AGP 7, and I want to convert my project to use Java 11. Apparently just doing the following does not work as mentioned on https://developer.android.com/studio/preview/features#use-java-11:
android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
// For Kotlin projects
kotlinOptions {
jvmTarget = "11"
}
}
I get the following error when I build:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':app:androidJdkImage'.
> Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JdkImageTransform: /Users/azfarsiddiqui/Library/Android/sdk/platforms/android-30/core-for-system-modules.jar.
> jlink executable /Applications/Android Studio Preview.app/Contents/jre/jdk/Contents/Home/bin/jlink does not exist.
* 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.
To keep it simple, I've been trying this on a Jetpack Compose sample project here: https://github.com/android/compose-samples/tree/main/JetNews
Any thoughts? Thanks guys
Android Studio Artic Fox 2020.3.1
Preferences (Settings) -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JDK -> Select JDK 11 or download JDK
Before
I assume you have Java 11 or later installed. Following steps:
File -> Project Structure -> SDK Location -> Change JDK Location to the Java 11 jdk folder
If you are using Mac OS then try to search for that folder in:
/Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home
这篇关于如何将 Android 项目升级到 Java 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!