Default interface methods are only supported starting with Android N

运行环境

  • Android Studio 4.1.1
  • compileSdkVersion 29
  • buildToolsVersion "29.0.2"

点击绿色锤子「make project」出现以下错误

Default interface methods are only supported starting with Android N (--min-api 24): 
    Landroidx/room/migration/AutoMigrationCallback;onPostMigrate(Landroidx/sqlite/db/SupportSQLiteDatabase;)V

解决办法:

在模块的gradle里的android部分加上compileOptions指定Java版本

android {
    // ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

再锤一次就ok了

同理,出现类似的only supported starting with Android N时,也可以用上面指定Java版本的方法

Static interface methods are only supported starting with Android N (--min-api 24): 
    int androidx.constraintlayout.core.motion.utils.TypedValues$Attributes.getId(java.lang.String)
posted @ 2021-10-25 08:21  AnRFDev  阅读(412)  评论(0编辑  收藏  举报