-2

I am creating a project in Android Studio using LibGDX, musicg and jlayer. The problem is when using any class from these libraries in the core project the error java.lang.NoClassDefFoundError appears. I have the libraries in jar on the folder libs of the core project.

It is not a multidex error since my project only has 18k methods.

Screenshots from the error and the gradle build:

Log Error

W/dalvikvm: threadid=12: thread exiting with uncaught exception (group=0x41a2bc98)
W/dalvikvm: threadid=12: uncaught exception occurred
W/System.err: java.lang.NoClassDefFoundError: javazoom.jl.converter.Converter
W/System.err:     at com.beatshare.game.Utilities.Utils.sync(Utils.java:129)
W/System.err:     at Screens.ListMusicScreen.show(ListMusicScreen.java:44)
W/System.err:     at com.badlogic.gdx.Game.setScreen(Game.java:61)
W/System.err:     at Screens.MainMenuScreen$2.touchUp(MainMenuScreen.java:86)
W/System.err:     at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:58)
W/System.err:     at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:353)
W/System.err:     at com.badlogic.gdx.backends.android.AndroidInput.processEvents(AndroidInput.java:379)
W/System.err:     at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:457)
W/System.err:     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1814)
W/System.err:     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1517)
W/dalvikvm: threadid=12: calling UncaughtExceptionHandler
E/AndroidRuntime: FATAL EXCEPTION: GLThread 794
                  Process: com.beatshare.game, PID: 29535
                  java.lang.NoClassDefFoundError: javazoom.jl.converter.Converter
                      at com.beatshare.game.Utilities.Utils.sync(Utils.java:129)
                      at Screens.ListMusicScreen.show(ListMusicScreen.java:44)
                      at com.badlogic.gdx.Game.setScreen(Game.java:61)
                      at Screens.MainMenuScreen$2.touchUp(MainMenuScreen.java:86)
                      at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:58)
                      at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:353)
                      at com.badlogic.gdx.backends.android.AndroidInput.processEvents(AndroidInput.java:379)
                      at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:457)
                      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1814)
                      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1517)

Core build.gradle

apply plugin: "java"

sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


dependencies {
    compile 'com.google.code.gson:gson:2.8.0'
    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/jl1.0.1.jar')
    compile files('libs/musicg-1.4.2.0.jar')
}



eclipse.project {
    name = appName + "-core"
}

App build.gradle

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://repo1.maven.org/maven2/" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'

    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "Beatshare"
        gdxVersion = '1.9.6'
        roboVMVersion = '2.3.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }

}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
    }
}

project(":core") {
    apply plugin: "java"
    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"


    }

}

tasks.eclipse.doLast {
    delete ".project"
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Llop
  • 1
  • 3
  • you can put your code and error log here instead of screenshot ? – Abhishek Aryan Apr 10 '17 at 16:56
  • Sorry, new to the site. But added the gradle code and error log. – Llop Apr 10 '17 at 20:33
  • Are you aware of what `compile fileTree(include: ['*.jar'], dir: 'libs')` does? You do not need the two lines after it – OneCricketeer Apr 10 '17 at 20:33
  • Yes, I know that will compile all jars on the libs folder but I wrote the other two just for paranoia. Tried everything with gradle to fix the error but nothing works. – Llop Apr 10 '17 at 23:13

1 Answers1

0

jlayer.jar available in maven repo so compile in this way and remove jlayer.jar from libs folder:

dependencies {
    compile 'com.google.code.gson:gson:2.8.0'
    compile group: 'javazoom', name: 'jlayer', version: '1.0.1'
    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    compile fileTree(include: ['*.jar'], dir: 'libs')   
}

java.lang.NoClassDefFoundError

This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it.

This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again).

The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65