I'm new to java/android so I'm hoping this is a pretty easy thing to solve.
I've used libGDX's setup to create a project, which I then imported to Android Studio. I didn't know the Supplier
interface was only available to Java 8, and used it in the core module, which as far as I understand, it compiles into a library that is shared by all android/html/desktop/ios versions of the game. The desktop version runs fine (I have Java 8 installed), but my android app crashes with a NoClassDefFoundError
error (BTW, the error message was showing the name of classes that I wrote, and not Supplier
, but the error disappeared as soon as I removed every reference to Supplier
and came back when I added them, so apparently the error message doesn't show the actual problem class).
If I try to use Supplier
in my android module, it won't even let me import the class, so it knows it doesn't support that Java version, but it'll happily let me use it in the core module without any warning. I'm sure removing references to Supplier
will solve the problem, but this fix may cause runtime errors later on if I inadvertently use any Java 8 features, so not a good way to solve it.
I don't know where in the project is it set to use Java 8, and there seem to be a bunch of .gradle, .xml and .iml files which apparently are all related to configuration. Here is my build.gradle
file in the core module:
apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-core"
}
Android studio shows the sourceCompatibility = 1.6
line grayed out and says "Assignment is not used" when I hover over it. So that may be part of the problem.
My core.iml
file contains this line too:
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
Also, here is the core
section in the root build.gradle
file:
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
}
}
So, what should I change to prevent it from letting me use Java 8 in my core project?