android studio error: Default interface methods ar

2019-01-22 05:54发布

问题:

i upgraded to android studio 3.1 and im 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)}

here is my gradle config:

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

as you can see i am targetting 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 wont i be missing alot of customers ? why was i not getting this error before i upgraded 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 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 ?

here are my 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'
    }

回答1:

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
    }
...
}