Default interface methods are only supported starting with Android 7.0 (Nougat)

問題:

I upgraded to Android Studio 3.1 and I'm getting the following error:我升級到 Android Studio 3.1,但出現以下錯誤:

Default interface methods are only supported starting with Android N (--min-api 24): void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner)僅從 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)} Message{kind=ERROR, text=默認接口方法僅支持從 Android N (--min-api 24) 開始: void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner), sources=[未知源文件],工具名稱=Optional.of(D8)}

錯誤

Here is my Gradle configuration:這是我的 Gradle 配置:

compileSdkVersion 27
//buildToolsVersion '27.0.3'
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 27
     multiDexEnabled true
     //...
   }

As you can see, I am targeting 27 which is already ahead of 24 that it's complaining about.如您所見,我的目標是 27,這已經超過了它所抱怨的 24。 What exactly should I do to fix this?我到底應該怎麼做才能解決這個問題? If I change to 1.8 Java, won't I be missing a lot of customers?如果我改成1.8 Java,會不會錯過很多客戶? Why was I not getting this error before I upgraded Android Studio?爲什麼我在升級 Android Studio 之前沒有收到此錯誤?

I do not know if this is about the LifecycleObserver class I recently put in. It was in Kotlin and now I changed it to Java, but I still get the same error after cleaning the project:不知道是不是我最近放的 LifecycleObserver 類的問題。它是在 Kotlin 中的,現在我將其更改爲 Java,但是我在清理項目後仍然出現相同的錯誤:

public class LifeCycleAwareObserver implements LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void  onAppBackgrounded() {
        AnalyticsUtils.trackStartSession(true);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onAppForegrounded() {
        AnalyticsUtils.trackStartSession(false);
    }
}

How can I trace where the error is coming from so I can fix it?我如何追蹤錯誤來自哪裏,以便我可以修復它?

Here are my version dependencies:這是我的版本依賴項:

project.ext {

        firebase_version = '12.0.0'

        supportlib_version = '27.0.2'

        room_version = '1.0.0'

        espresso_version = '3.0.1'

        archLifecycleVersion = '1.1.1'
    }

解決方案:

參考一: https://en.stackoom.com/question/3LkUn
參考二: https://stackoom.com/question/3LkUn
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章