问题:
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