1. 程式人生 > >8、D8: Default interface methods are only supported starting with Android N (--min-api 24): void

8、D8: Default interface methods are only supported starting with Android N (--min-api 24): void

source cycle over starting lan adl art creat lifecycle

1、錯誤信息

升級完 Android N 後,有些項目運行起來報錯信息大致如下:

Default interface methods are only supported starting with Android N (--min-api 24): 
void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner) Message{kind=ERROR, text=Default interface methods are only supported starting with Android N (--min-api 24):
void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner),
sources=[Unknown source file], tool name=Optional.of(D8)}

2、解決方法

在 app 下的 build.gradle 文件 android 界面點加入:compileOptions

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

原文地址:https://stackoverflow.com/questions/49512629/android-studio-error-default-interface-methods-are-only-supported-starting-with/49525685

8、D8: Default interface methods are only supported starting with Android N (--min-api 24): void