Home » Android » android – java.lang.NoClassDefFoundError (libgdx)

android – java.lang.NoClassDefFoundError (libgdx)

Posted by: admin June 15, 2020 Leave a comment


Been trying to work with the Libgdx framework and have been experiencing some frustrating issues.. I’m following a tutorial and I’m unable to run my project. What am I doing wrong?

package com.mygdx.game.android;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class AndroidLauncher implements ApplicationListener {

    SpriteBatch batch;
    Texture mario;

    public void create() {
        batch = new SpriteBatch();

        mario = new Texture(Gdx.files.internal("mario.png"));

    public void resize(int width, int height) {
        // TODO Auto-generated method stub


    public void render() {

        batch.draw(mario, 50, 50);


    public void pause() {
        // TODO Auto-generated method stub


    public void resume() {
        // TODO Auto-generated method stub


    public void dispose() {
        // TODO Auto-generated method stub



Here’s what the console displays when I run the project:

Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/jnigen/NativeCodeGenerator
    at com.badlogic.gdx.utils.GdxBuild.main(GdxBuild.java:34)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.jnigen.NativeCodeGenerator
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 1 more
How to&Answers:

I had the same problem, but realised that I was running GdxBuild instead. Ensure that you right click on DesktopLauncher.java > Run As > Java Application.


In my case it was my first libGDX project, I was running it using Android Studio version 3.0.1 on KUBUNTU, and as soon as I imported the freshly created project using gdx-setup.jar (Setup App) to Android Studio a popup message was asking informing me to update Gradle which I did, and that broke the project.

enter image description here

create a new libGDX project and import it without updating Gradle (click “Don’t remind me again for this project“) and it should work.


Rigth click project- properties – build options – order and export and check all gdx libraries. Thats probably it, that error comes when it cant find a class at runtime.


I had the same problem, and the only way I could reproduce it was by using a desktop configuration. So instead of using a desktop configuration, run it as a gradle config. In the command line, that would be:

gradlew desktop:run

Since it’s a pain manually doing that every single time you want to run the project, create a new Gradle run configuration

Press the plus icon and select "Gradle"

If you pick the Gradle project in the run config to be the sub module, all you need to type as the task is gradlew run instead of gradlew desktop:run.

You have to define the memory flags in the VM option input (does not have to have these values though):

-Xmx2G -Xms128M

Script parameters can remain empty. Note that this entire thing counts as a Gradle build, so you have to kill the process (if it’s running) before you can launch a new one.

I can export a jar without problems, so you should be fine in production.

TL:DR; Use a Gradle run config with gradlew desktop:run instead of using an application


So many different answers. Rather than follow them all I created a new project. As simply as possible; if upgrading IntelliJ will break my project I’ll want less unused features to drag into 2018.

I was getting

java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener

Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener

After upgrading IntelliJ from 2017.3 to 2018.1.

This time I didn’t tick any boxes with:

simplest libgdx setup

and similarly for the “Advanced” settings:

simplest advanced settings

Without IDEA selected the project took 10s to generate and gave different instructions on how to import which met with markedly more success (The old ways are the best remembered, Eclipse anyone?).

Of course I got a few more errors but nothing I hadn’t overcome before in getting a new project off the ground. After that it’s just a matter of copying the old files over. One more hint, no matter what settings IntelliJ offers to open to set your Java level to 1.7, the Gradle files don’t get touched and so you must hunt the remaining 1.6 references manually.


Right Click -> Run As -> Run Configurations -> Click Desktop-Launcher in the menu on the left and then click run, this should fix it.


Project structure -> modules -> choose required module (desktop, android, etc) -> Dependencies -> Add Library.

Don’t forget change Scope from “Provided” to “Compile”.