Default interface methods are only supported starting with Android N

June 21, 2019

依赖旧版本:

1
2
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'

更新为以下版本:

1
2
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-alpha02'

构建时出现错误:

1
Error: Default interface methods are only supported starting with Android N (--min-api 24): android.view.MenuItem androidx.core.internal.view.SupportMenuItem.setContentDescription(java.lang.CharSequence)

按照以下步骤,先点击 Android Studio 右上角 Project Structure 图标(右二)

project_structure_icon

在该设置中选择 app 模块,把 Source CompatibilityTarget Compatibility 均设置为 1.8

project_structure

当然,也可以手动在 build.gradle(Module:app) 中添加代码:

1
2
3
4
 compileOptions {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
}

这是添加完成后的效果,继续编译即可

compileOptions