android - 此编译器不支持 API 级别 31。请使用 30 或更早的 API 级别

标签 android android-studio

我将现有的 android 项目升级到 API 级别 31。我使用 Java 作为语言。我改变了 build.gradle

compileSdkVersion 31
defaultConfig {
    applicationId 'com.app.app'
    minSdkVersion 16
    targetSdkVersion 31
    versionCode 91
    versionName '4.0.1'
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
但我无法使用 AVD 或真实设备调试应用程序。我收到这个错误。
> Task :app:mergeProjectDexDebug
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier
我想我需要更新编译器,我该怎么做?

最佳答案

尝试将此添加到您的 build.gradle 文件:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  kotlinOptions {
    jvmTarget = '1.8'
  }
}

关于android - 此编译器不支持 API 级别 31。请使用 30 或更早的 API 级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70312198/

相关文章:

java - 试图让自定义 android 相机工作

android - 扩大最大宽度的ListView中的ImageView

java - Android 上的应用程序重新启动后,线程才会启动

java - 我想在一项 Activity 中显示两个自定义对话

android - 使用 Android Studio 的织物

git - Android studio git 使用私钥

android - buildToolsVersion 范围或 gradle 中的 '+'

Android - 如何检查我的应用程序之前是否已安装到设备?

android - Sugar ORM 不会创建表

Android 键盘覆盖 View ,但仅在全屏模式下