4

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

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

谢谢您的帮助!

4

3 回答 3

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

于 2014-01-06T14:25:38.380 回答
0

我在使用 LibGDX 设置 Proguard 时遇到了麻烦,最后看到了这篇方便的 Stack Overflow 帖子。问题是,尽管它解决了最初的问题,但它留下了另一个更令人费解的问题:“找不到方法:[...]/badlogic/gdx/physics/box2d/World;.beginContact:(J)V”。

经过一番谷歌搜索后,我最终找到了这篇文章:找不到方法

建议使用以下设置:

-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 问题和无法识别的方法。之后,该应用程序在移动设备上运行得很好。

希望它可以帮助任何人。

于 2014-06-18T05:51:30.140 回答
0

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

下面为我​​工作

创建一个新的 libgdx 项目,您可以保留相同的包和文件夹名称,以便您可以从旧项目复制到它们

于 2016-04-24T12:28:06.123 回答