gpt4 book ai didi

java - 在 Android Studio (Java, Android) 中使用 JDK17 & Record

转载 作者:行者123 更新时间:2023-12-04 23:53:53 29 4
gpt4 key购买 nike

enter image description here
第1部分 :-
拿到这个版本的Android Studio后,我可以使用了JDK17 在我的项目中。
一切正常,没有构建失败,没有运行时错误等。
(就像增强型开关工作正常)
....但是这个警告在每次构建期间都会不断出现。有没有办法压制 这个?
enter image description here
(警告文本 -> “一个或多个类的文件版本 >= 56,不受官方支持”)
这些是 build.gradle 文件:
(1):-

buildscript {

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-rc01'
classpath 'com.google.android.gms:strict-version-matcher-plugin:1.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
(2):-
apply plugin: 'com.android.application'
apply plugin: 'com.google.android.gms.strict-version-matcher-plugin'

android {
compileSdkVersion 32
buildToolsVersion '32.0.0'
defaultConfig {
applicationId "com.Sujal_Industries.SelfEmot"
minSdkVersion 21
targetSdkVersion 32
versionCode 11
versionName "1.3.1"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0-alpha01'
implementation 'androidx.core:core-splashscreen:1.0.0-beta01'
implementation 'com.google.mlkit:image-labeling:17.0.6'
implementation 'com.google.android.material:material:1.6.0-alpha01'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'io.reactivex.rxjava3:rxjava:3.1.3'
}
(我尝试搜索类似的警告但没有运气)
第2部分 :-
最近,我发现 Android Studio 现在显示了创建新 Java 的选项。记录 .
enter image description here
但是当我创建一个并构建项目时,会弹出这个错误:
enter image description here
所以..有什么办法可以强制添加 记录 java.lang 包中的类?
(如果需要更多信息/澄清,请告诉我)
编辑 : 我知道 11 以上的版本不是 官方支持,但没有解决方法吗?

最佳答案

第一部分:
警告意味着您的项目中有一个或多个类不支持高于 11 的 Java 版本。
您的项目有一些依赖项不是为 JDK 17 编译的。那是因为 Android 目前不支持 Java 17。
这意味着您正在混合产生此警告的不同版本的 Java 位码。
Java Version Numbers
第二部分:
您正在尝试使用 Android 当前不支持的记录。
摘要:
您已将项目的 Java 版本设置为 Java 17,目前不支持该版本:

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
您目前可以达到的最高值是 Java 11
这意味着您必须将 compileOptions 更改为:
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

关于java - 在 Android Studio (Java, Android) 中使用 JDK17 & Record,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70784107/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com