Search code examples
javaandroidintellij-ideagradlelibgdx

LibGDX ClassNotFound on Android


I'm using libGDX for my game which shares some code with another project. I put this code in a .jar library which I have added in the root build.gradle.

Everything works fine on desktop, but when I launch the game on Android it crashes with a ClassNotFound exception. It can't find a class of my the library.

Can anyone help me out? I have no idea what is causing the problem.

Edit: changes to build.gradle:

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile fileTree(dir: '../libs', include: '*.jar')
    }
}

Solution

  • You need to add the same fileTree dependency directly in the android module because the Android Gradle plugin currently can't handle transitive flat file dependencies.

    project(":core") {
       ...
       compile fileTree(dir: '../libs', include: '*.jar')
       ...
    }
    
    // And also
    
    project(":android") {
       ...
       compile fileTree(dir: '../libs', include: '*.jar')
       ...
    }
    

    Source.