4

I'm developing an android live wallpaper with libgdx and I've got a big problem when I use proguard. This is the error when my livewallpaper is starting:

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.o.a(Unknown Source)
08-17 13:55:50.755: E/AndroidRuntime(28276):    at com.badlogic.gdx.backends.android.q.a(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!

Domenico Maiuri
  • 191
  • 1
  • 1
  • 10
  • 1
    Have you tried to add something like `-keep class * com.badlogic.gdx.**` to keep the libgdx classes untouched? Why would you want do obfuscate them anyway, they are open source... – noone Aug 19 '13 at 10:49

3 Answers3

2

I had a similar issue with obfuscation of 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 noone's answer, or:

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

This was logged and answered in the issue tracker for libgdx: https://code.google.com/p/libgdx/issues/detail?id=1215

stormont
  • 539
  • 5
  • 16
0

I had trouble setting up Proguard with LibGDX, and ended up on this handy Stack Overflow post. The problem was that even though it solved the initial problem, it left another more puzzling one: "method not found: [...]/badlogic/gdx/physics/box2d/World;.beginContact:(J)V".

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

It recommends to use the following settings:

-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 @stormont's first settings and the posts settings fixed my problem with LibGdx and the method not being recognized. After that the application ran on a mobile device just fine.

Hope it helps anybody.

cavpollo
  • 4,071
  • 2
  • 40
  • 64
0

My app still throws this error even when proguard was turned off.

Below worked for me

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

Habeeb
  • 41
  • 2