Error: Default interface methods are only supported starting with Nougat (--min-api 24) when NOT using them

Viewed 4163

I'm getting the following error from android-studio when compiling my libgdx game:

Error: Default interface methods are only supported starting with 
Android N (--min-api 24): com.hgames.core.item.Item 
com.hgames.core.item.misc.MiscItem.deepClone()

which I don't understand because I don't use default interface methods. My code compiles fine with a JDK1.7. The error reported here concerns the following code:

interface Item {

   Item deepClone()

} 

interface MiscItem extends Item {

  @Override
  MiscItem deepClone()

}

There is no default method in there. Note that if I remove this overriding, and add a cast to MiscItem at call sites, the compiler reports goes to the next error (of the same kind), as I'm using this pattern in a number of places. I'm using gradle and have the following in my build.gradle file:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 15
    compileSdkVersion 15
    versionCode 1
}

I am new to android-studio as I usually use Eclipse, but switched to android-studio to port my game to Android. So maybe I'm missing something dumb, but I could not find any help whatsoever anywhere.

1 Answers

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