Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProGuard obfuscation - java.lang.NoSuchMethodError: getPointer

I am trying to obfuscate a game that I wrote. I slimmed it down to a very basic project to illustrate the problem (the project can be found here: https://github.com/dschneider/libgdx-proguard-test).

You have to install ant and run make desktop in terminal to compile and obfuscate the project. The following error occurs when trying to run the obfuscated jar afterwards:

Exception in thread "main" java.lang.NoSuchMethodError: getPointer
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1894)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at org.lwjgl.Sys$1.run(Sys.java:70)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.b(Sys.java:66)
at org.lwjgl.Sys.c(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.openal.AL.<clinit>(AL.java:59)
at com.badlogic.gdx.backends.openal.OpenALAudio.<init>(OpenALAudio.java:70)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:82)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:64)
at com.libgdxproguard.test.Main.main(Main.java:14)

Am I missing something? When I tell ProGuard to not obfuscate the code, it works afterwards. Apparently something is obfuscated what shouldn't be obfuscated, but I am not sure how to solve this error.

like image 495
RaceCondition Avatar asked Dec 06 '25 06:12

RaceCondition


1 Answers

The native code in liblwjgl.so calls back to the Java code of the LWJGL library, using reflection. ProGuard isn't aware of anything that the native code does, so it may remove or rename the classes, fields, and methods, which breaks the reflection. The simplest solution is to tell ProGuard to preserve all of them with their original names:

-keep class org.lwjgl.** { *; }

The same is happening with libgdx.so in the GDX library, so:

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

You could refine this configuration by figuring out more precisely which classes, fields, and methods need to be preserved.

like image 144
Eric Lafortune Avatar answered Dec 08 '25 19:12

Eric Lafortune