Proguard和libgdx:RuntimeException

时间:2013-08-17 12:31:58

标签: libgdx proguard wallpaper runtimeexception

我正在使用libgdx开发一个Android动态壁纸,当我使用proguard时,我遇到了一个大问题。这是我的livewallpaper开始时的错误:

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): 

这是我的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

感谢您的帮助!

3 个答案:

答案 0 :(得分:2)

我对AndroidInput类的混淆有类似的问题。这足以使用:

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

...而不是没有人的回答,或者:

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

在libgdx的问题跟踪器中记录并回答了这个问题:https://code.google.com/p/libgdx/issues/detail?id=1215

答案 1 :(得分:0)

我无法使用LibGDX设置Proguard,最终得到了这个方便的Stack Overflow帖子。问题是,即使它解决了最初的问题,它又留下了另一个令人费解的问题:“未找到方法:[...] / badlogic / gdx / physics / box2d / World; .beginContact:(J)V”。< / p>

经过一些谷歌搜索后,我结束了这篇文章:method not found

建议使用以下设置:

-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 {
   *;
}

@ stormont的第一个设置和帖子设置的组合修复了我的LibGdx问题并且方法无法被识别。之后,应用程序在移动设备上运行就好了。

希望它可以帮助任何人。

答案 2 :(得分:0)

即使关闭了proguard,我的应用仍然会抛出此错误。

以下为我工作

创建一个新的libgdx项目,你可以保留相同的包和文件夹名称,这样你就可以从旧项目中复制它们