仅从 Android 7.0 (Nougat) 开始支持默认接口方法 [英] Default interface methods are only supported starting with Android 7.0 (Nougat)
问题描述
我升级到 Android Studio 3.1,但出现以下错误:
I upgraded to Android Studio 3.1 and I'm getting the following error:
默认接口方法仅支持从 Android N (--min-api 24) 开始: void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner)
Message{kind=ERROR, text=默认接口方法仅支持从 Android N (--min-api 24) 开始: void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner), sources=[未知源文件],工具名称=Optional.of(D8)}
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)}
这是我的 Gradle 配置:
Here is my Gradle configuration:
compileSdkVersion 27
//buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
multiDexEnabled true
//...
}
如您所见,我的目标是 27,这已经超过了它所抱怨的 24.我到底应该怎么做才能解决这个问题?如果我换成1.8 Java,会不会流失很多客户?为什么我在升级 Android Studio 之前没有收到此错误?
As you can see, I am targeting 27 which is already ahead of 24 that it's complaining about. What exactly should I do to fix this? If I change to 1.8 Java, won't I be missing a lot of customers? Why was I not getting this error before I upgraded Android Studio?
我不知道这是不是我最近放入的 LifecycleObserver 类.它是在 Kotlin 中的,现在我将其更改为 Java,但清理项目后仍然出现相同的错误:
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:
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?
这是我的版本依赖项:
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'
}
推荐答案
如CommonsWare 提到,在里面添加这个供参考在 build.gradle 中为您的应用模块(应用级别)添加 android {...}
闭包以解决问题:
As CommonsWare mentioned, for reference add this inside the android {...}
closure in the build.gradle for your app module (app level) to resolve the issue:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
这篇关于仅从 Android 7.0 (Nougat) 开始支持默认接口方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!