Proguard and libgdx: RuntimeException

I am developing android live wallpapers with libgdx and I have a big problem when I use proguard. This is a mistake when my personal life begins:

08-17 13:55:50.755: E/AndroidRuntime(28276): FATAL EXCEPTION: main 08-17 13:55:50.755: E/AndroidRuntime(28276): java.lang.RuntimeException: Couldn't construct AndroidInput, this should never happen 08-17 13:55:50.755: E/AndroidRuntime(28276): at com.badlogic.gdx.backends.android.oa(Unknown Source) 08-17 13:55:50.755: E/AndroidRuntime(28276): at com.badlogic.gdx.backends.android.qa(Unknown Source) 08-17 13:55:50.755: E/AndroidRuntime(28276): at com.badlogic.gdx.backends.android.r.onCreate(Unknown Source) 08-17 13:55:50.755: E/AndroidRuntime(28276): at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:777) 08-17 13:55:50.755: E/AndroidRuntime(28276): at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:1037) 08-17 13:55:50.755: E/AndroidRuntime(28276): at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40) 08-17 13:55:50.755: E/AndroidRuntime(28276): at android.os.Handler.dispatchMessage(Handler.java:99) 08-17 13:55:50.755: E/AndroidRuntime(28276): at android.os.Looper.loop(Looper.java:137) 08-17 13:55:50.755: E/AndroidRuntime(28276): at android.app.ActivityThread.main(ActivityThread.java:5227) 08-17 13:55:50.755: E/AndroidRuntime(28276): at java.lang.reflect.Method.invokeNative(Native Method) 08-17 13:55:50.755: E/AndroidRuntime(28276): at java.lang.reflect.Method.invoke(Method.java:511) 08-17 13:55:50.755: E/AndroidRuntime(28276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) 08-17 13:55:50.755: E/AndroidRuntime(28276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 08-17 13:55:50.755: E/AndroidRuntime(28276): at dalvik.system.NativeStart.main(Native Method) 08-17 13:55:50.755: E/AndroidRuntime(28276): Caused by: java.lang.NoSuchMethodException: <init> [interface com.badlogic.gdx.a, class android.content.Context, class java.lang.Object, class com.badlogic.gdx.backends.android.a] 08-17 13:55:50.755: E/AndroidRuntime(28276): at java.lang.Class.getConstructorOrMethod(Class.java:460) 08-17 13:55:50.755: E/AndroidRuntime(28276): at java.lang.Class.getConstructor(Class.java:431) 08-17 13:55:50.755: E/AndroidRuntime(28276): 

And this is my proguard.cfg:

 -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -dontwarn java.awt.** -dontnote java.awt.** -dontwarn com.badlogic.gdx.jnigen.** -dontwarn com.moribitotech.mtx.** -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class com.android.vending.licensing.ILicensingService -keep class com.bugsense.trace.models.** { *; } -keepclassmembers class **.MraidView$JavaScriptInterface { *; }-keepclassmembers class **.SmartWallActivity$AppWall$JavaScriptInterface { *; } -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -keepclasseswithmembers class **.R$** { public static <fields>; } -keep class * extends android.view.View { public <init>(android.content.Context); public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); void set*(***); *** get*(); } -keepclassmembers class * { static final % *; static final java.lang.String *; } -keepattributes SetJavaScriptEnabled -keepattributes JavascriptInterface -keepattributes InlinedApi -dontwarn com.bugsense.trace.models.** -keep public class cmn.Proguard$KeepMembers -keep public class * implements cmn.Proguard$KeepMembers -keepclassmembers class * implements cmn.Proguard$KeepMembers { <methods>; } -keepattributes *Annotation* -dontwarn android.webkit.JavascriptInterface 

Thank you for your help!

+4
source share
3 answers

I had a similar problem with obfuscating the AndroidInput class. It is enough to use:

 -keepnames class com.badlogic.gdx.backends.android.AndroidInput* -keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {<init>(...);} 

... instead of answering one or:

 -keep class com.badlogic.gdx.backends.android.** { *; } 

This was recorded and answered the questionnaire for libgdx: https://code.google.com/p/libgdx/issues/detail?id=1215

+2
source

I had problems setting up Proguard with LibGDX, and it turned out to be on this convenient thing. The problem was that although it solved the original problem, it left another bewilderment: "the method was not found: [...] / badlogic / gdx / physics / box2d / World; .beginContact: (J) V".

After some googling, I ended up on this post: method not found

The following settings are recommended:

 -dontwarn com.badlogic.gdx.jnigen.** -dontwarn com.badlogic.gdx.backends.** -keep class com.badlogic.gdx.** -keepclasseswithmembers class * implements com.badlogic.gdx.physics.box2d { *; } -keepclasseswithmembers class com.badlogic.gdx.physics.box2d { *; } -keepclasseswithmembers class com.badlogic.gdx.physics.box2d.World { *; } 

The combination of the first @stormont settings and message settings fixed my problem with LibGdx and a method that is not recognized. After that, the application runs on a mobile device just fine.

Hope this helps anyone.

0
source

My application still throws this error even when proguard is disabled.

Below worked for me

create a new libgdx project and you can keep the same package and folder names so you can copy them from the old project

0
source

Source: https://habr.com/ru/post/1497576/


All Articles