23

I made a game using libgdx and it runs fine on both desktop and android before. I'm not sure if its because I started using box2d physics engine and liquidfun particles,what basically happens is that when I click play on my game it start loading then after loading it should go to the gameScreen, but it crashes then says "Unfortunately, myGame has stopped".

error message:

E/AndroidRuntime: FATAL EXCEPTION: GLThread 3764
Process: com.nivekbryan.puffypuff, PID: 8416
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/badlogic/gdx/physics/box2d/World;

I followed this setup tutorial on how to port liquidfun library, its from 2014 kinda old. The game runs Ok as desktop application.

This is my build.gradle file (dependencies), what could be the problem? and why is working as desktop application and not as an android application?

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.1.0'
    }
}

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

    version = '1.0'
    ext {
        appName = "Puffy Puff"
        gdxVersion = '1.9.3'
        roboVMVersion = '2.1.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
        admobVersion = '8.3.0'
    }

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

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


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"

        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        compile fileTree(dir: 'libs', include: '*.jar')
    }
}

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-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"
        compile "com.google.android.gms:play-services-ads:8.3.0"
        compile fileTree(dir: 'libs', include: '*.so')
    }
}

project(":ios") {
    apply plugin: "java"
    apply plugin: "robovm"


    dependencies {
        compile project(":core")
        compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
        compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"

        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
    }
}

project(":html") {
    apply plugin: "gwt"
    apply plugin: "war"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
        compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
    }
}

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')
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

UPDATE:

I found this solution link so what I did is I copied gdx-liquidfun.jar to Android -> libs then right click and add as library, but I still get the error. Help please, thanks in advance (I'm using Intellij Community Edition)

Community
  • 1
  • 1
Kevin Bryan
  • 1,846
  • 2
  • 22
  • 45
  • Might be a problem with you gradle, please add them to your question. – Marius Sep 29 '16 at 17:28
  • What's wrong with the below answer? You said the classes resolve, but some method isn't working, so seems you need to read the API documentation to find the correct parameters – OneCricketeer Nov 08 '16 at 15:27
  • @cricket_007 - I'm using LiquidFun for particles, LiquidFun is based on Box2d So when you use LiquidFun, world.step will need 4 parameters. But if I use plain Box2d then only 3 parameters are needed, the answer below will basically make me use box2d only, but I need LiquidFun for particles. – Kevin Bryan Nov 08 '16 at 15:31
  • So, you're saying that this `box2d.World` class operates differently depending on which library you are using? – OneCricketeer Nov 08 '16 at 15:39
  • @cricket_007 - yes but I think the problem is not on the dependencies, I think it's not able to find the class for android. I followed the setup tutorial except for the part where it says "If you don't have gdx-liquidfun.jar in Android Private Libraries it is necessary to edit build path of android project." Because I'm not familiar with eclipse and my IDE is Intellij – Kevin Bryan Nov 08 '16 at 15:46
  • 2
    Those eclipse instructions are the equivalent of `compile fileTree(dir: 'libs', include: '*.jar')` in Gradle and dropping the jar file into that libs folder. – OneCricketeer Nov 08 '16 at 15:50
  • 1
    @ cricket_007 - OMG it worked! so I copied the gdx-liquidfun.jar to android -> libs, then on my main build.gradle under android dependencies I added - compile fileTree(dir: 'libs', include: 'gdx-liquidfun.jar'). Thanks, and the bounty? – Kevin Bryan Nov 08 '16 at 16:04

1 Answers1

1

Put this in the android dependencies:

    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-x86"

and this in core dependencies:

    compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
M1LKYW4Y
  • 598
  • 1
  • 4
  • 19
  • I tried it but now I get an error on //world.step(1 / 60f, 6, 2, 1); In regular box2d you don't need the 1 but since I'm also using liquidfun then I need that 4th parameter. And if I just do world.step(1 / 60f, 6, 2) the error is removed but once loaded the game crashes, telling me that the required is (float, int, int ,int) – Kevin Bryan Oct 23 '16 at 13:18
  • If you want to use liquidfun then not include box2d in your project. liquidfun depend on a jar that is different from box2d jar. step method of box2d world take three argument but liquidfun dependent jar having world that take 4 argument. – Abhishek Aryan Jan 05 '17 at 16:20