5

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 2
    Did you try to use Java 8 as indicated in this [question](https://stackoverflow.com/questions/49512629/android-studio-error-default-interface-methods-are-only-supported-starting-with) ? – Benoit Dec 18 '18 at 12:39
  • 1
    Yes it solves the issue, but it puzzles me; I need to specify a source compatibility higher than what the actual source supports ^^ Thanks! – Clément hgames Dec 18 '18 at 14:24

1 Answers1

2

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
    }
...
}
Aniket
  • 441
  • 5
  • 8