仅从Android N开始支持默认接口方法 [英] Default interface methods are only supported starting with Android N
问题描述
我已升级到android studio 3.1,但出现以下错误:
I upgraded to android studio 3.1 and I'm getting the following error:
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 config:
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 its 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 still get the same error after cleaning 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 to 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 to resolve issue:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
这篇关于仅从Android N开始支持默认接口方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!