Search code examples
javaandroidlibgdxbulletphysicsbullet

Libgdx bulletwrapper app crashes when using proguard


My libgdx/bullet app crashes with the following exception when I try to run a release apk built with proguard enabled :

     Process: com.my.app, PID: 14042
     java.lang.NoSuchMethodError: no static method "Lcom/badlogic/gdx/physics/bullet/linearmath/LinearMathJNI;.SwigDirector_btIDebugDraw_getDefaultColors(Lcom/badlogic/gdx/physics/bullet/linearmath/btIDebugDraw;)J"
         at com.badlogic.gdx.physics.bullet.linearmath.LinearMathJNI.swig_module_init(Native Method)
         at com.badlogic.gdx.physics.bullet.linearmath.LinearMathJNI.<clinit>(Unknown Source)
         at com.badlogic.gdx.physics.bullet.linearmath.LinearMathJNI.btGetVersion(Native Method)
         at com.badlogic.gdx.physics.bullet.linearmath.a.a(Unknown Source)
         at com.badlogic.gdx.physics.bullet.a.a(Unknown Source)
         at com.my.app.i.<init>(Unknown Source)
         at com.my.app.h$1.a(Unknown Source)
         at com.badlogic.gdx.f.a.b.b.a(Unknown Source)
         at com.badlogic.gdx.f.a.b.a(Unknown Source)
         at com.badlogic.gdx.f.a.b.a(Unknown Source)
         at com.badlogic.gdx.f.a.a.a.a(Unknown Source)
         at com.badlogic.gdx.f.a.a.a$1.a(Unknown Source)
         at com.badlogic.gdx.f.a.b.c.a(Unknown Source)
         at com.badlogic.gdx.f.a.g.a(Unknown Source)
         at com.badlogic.gdx.f.a.h.b(Unknown Source)
         at com.badlogic.gdx.backends.android.i.onDrawFrame(Unknown Source)
         at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1548)
         at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1259)

My app is a game and the crash happens only when the game screen starts, not in the initial menu screens. This is my proguard-project.txt file:

-verbose

-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild
-dontwarn com.badlogic.gdx.jnigen.*

-keep class com.badlogic.gdx.controllers.android.AndroidControllers

-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
   <init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}

-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
   boolean contactFilter(long, long);
   void    beginContact(long);
   void    endContact(long);
   void    preSolve(long, long);
   void    postSolve(long, long);
   boolean reportFixture(long);
   float   reportRayFixture(long, float, float, float, float, float);
}

how do I solve this? I guess I need to prevent proguard from obfuscating the bullet calls but can't figure out how to do it.


Solution

  • -keep class com.badlogic.** { *; }
    -keep enum com.badlogic.** { *; }
    

    Source: this gradle file.

    Also I would be reluctant to have so many -dontwarns. After applying the above see if you can remove them. Only -dontwarn when you know it's really not a problem and have exhausted other ways to fix the warning.