在proGuard之后从Bundle获取int [] []时出现ClassCastException

时间:2014-03-07 12:11:12

标签: android proguard classcastexception

我已经花了几天时间讨论过这个问题,但仍然无法理解它,也没有谷歌以某种方式与问题相关。

在我的游戏中,我有int[8][8]数组 - gameFieldArray。 为了在屏幕旋转或接听电话等期间保存游戏状态,我使用它将其放入onSaveInstanceState(Bundle outState)

中的Bundle
outState.putSerializable(SC.SAVE_GAME_FIELD, gl.getGameField());

然后在onCreate我检索了数组:

gameFieldArray = (int[][])savedInstanceState.getSerializable(SC.SAVE_GAME_FIELD);

一切正常,直到我开始发布签名的apk并将它们发送给朋友进行一些预发布测试。 签名的apk由proGuard处理,具有以下设置:

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontwarn android.support.**
-verbose

-dontoptimize
-dontpreverify

-keepattributes *Annotation*, SourceFile, LineNumberTable, Signature
-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 com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

 -keepclassmembers public class * extends android.view.View {
  void set*(***);
  *** get*();
 }

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
  public static <fields>;
}

#ACRA-specific:
-keep class org.acra.ACRA {
    *;
}

-keep class org.acra.ReportingInteractionMode {
    *;
}

-keepnames class org.acra.sender.HttpSender$** {
    *;
}

-keepnames class org.acra.ReportField {
    *;
}

-keep public class org.acra.ErrorReporter
{
    public void addCustomData(java.lang.String,java.lang.String);
    public void putCustomData(java.lang.String,java.lang.String);
    public void removeCustomData(java.lang.String);
}

-keep public class org.acra.ErrorReporter
{
    public void handleSilentException(java.lang.Throwable);
}

现在有关重现的步骤: 只有我的一个朋友才能重现这一点。我认为那是因为他拥有载有512 MB的Galaxy 9001。 当他上场时:

    1) he recieves call
    2) talks, hangs up
    3) game crashes

这是我从ACRA获得的:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.game.maxstr8/com.game.maxstr8.GameFieldForAI}: java.lang.ClassCastException: java.lang.Object[] cannot be cast to int[][]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.access$600(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4931)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to int[][]
at com.game.maxstr8.f.<init>(GameLogic.java:36)
at com.game.maxstr8.GameField.onCreate(GameField.java:192)
at com.game.maxstr8.GameFieldForAI.onCreate(GameFieldForAI.java:24)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
... 11 more
java.lang.ClassCastException: java.lang.Object[] cannot be cast to int[][]
at com.game.maxstr8.f.<init>(GameLogic.java:36)
at com.game.maxstr8.GameField.onCreate(GameField.java:192)
at com.game.maxstr8.GameFieldForAI.onCreate(GameFieldForAI.java:24)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.access$600(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4931)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)

没有其他手机(内存量较大)或模拟器转载此内容。 这只是当apk与proguard,没有它一切正常。 这只是在接听电话时。在游戏中只切换方向时 - 执行相同的代码但不会发生崩溃。

有人有任何线索吗?任何帮助调查这一点将不胜感激!

稍后添加: java.lang.ClassCastException: java.lang.Object[] cannot be cast to int[][] at com.game.maxstr8.f.<init>(GameLogic.java:36)实际上是

gameFieldArray = (int[][])savedInstanceState.getSerializable(SC.SAVE_GAME_FIELD);

- 从保存的Bundle中检索int [] []数组。

0 个答案:

没有答案