我的应用程序在模拟和真实的1.6设备上都能完美工作。然而,索尼Xperia X10系列(运行1.6)却因java.lang.verify错误而崩溃。This thread让我相信PROGART优化可能是罪魁祸首,但是如果是这样的话,在每个设备上运行1.6的问题,而不是X10?
下面是堆栈跟踪:

java.lang.VerifyError: com.twocell.walkabout.Animator
at com.twocell.walkabout.Main.void onCreate(android.os.Bundle)(SourceFile:197)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2443)
at android.app.ActivityThread.access$2100(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1815)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4263)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

下面是触发错误的代码(在名为“animator”的类中):
static void setLayoutAnimation_textFadeIn(ViewGroup vg, Context context)
{
    Animation text_fadeIn = AnimationUtils.loadAnimation(context, R.anim.text_fade_in);
    LayoutAnimationController controller = new LayoutAnimationController(text_fadeIn, 0.25f);
    vg.setLayoutAnimation(controller);
}

从以下位置调用:
LinearLayout HeaderBar_Text = (LinearLayout) findViewById(R.id.HeaderBar_Text);
Animator.setLayoutAnimation_textFadeIn(HeaderBar_Text, this); // this is line 197

这里是text_fade_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="1000"
    />
</set>

我无法访问x10,所以我依赖于通过acra传递的堆栈跟踪。
编辑(新信息):
好的,我找到了一个运行1.6的x10的旧仿真器图像,并重新创建了这个问题。结果,它/正在/仅在版本(proguard)上崩溃。关闭Proguard,它就能正常工作。为什么在地球上这只影响x10而不是每一个1.6设备是个问题。这里是一些新的信息,我已经收集了,因为我有模拟器…
在我的一些活动中,我使用overridePendingTransition更改为淡入效果,但是1.6不支持此功能,因此我使用名为versionhelper的助手类:
class VersionHelper
{
    static void overrideTransition(Context context)
    {
        ((Activity)context).overridePendingTransition(R.anim.activity_fade_in, R.anim.activity_fade_out);
    }
}

它是从Animator调用的:
static void overrideTransition(Context context)
{
    if (Build.VERSION.SDK_INT > 4)
    {
        VersionHelper.overrideTransition(context);
    }
}

这允许1.6设备运行其余的代码,而不会因为不支持的方法而崩溃(感谢mark murphy的这种技术)。
现在,堆栈跟踪额外的日志数据:
07-19 23:42:29.150: ERROR/dalvikvm(705): Could not find method android.app.Activity.overridePendingTransition, referenced from method com.twocell.walkabout.Animator.overrideTransition
07-19 23:42:29.150: WARN/dalvikvm(705): VFY: unable to resolve virtual method 14: Landroid/app/Activity;.overridePendingTransition (II)V
07-19 23:42:29.150: WARN/dalvikvm(705): VFY:  rejecting opcode 0x6e at 0x0012
07-19 23:42:29.150: WARN/dalvikvm(705): VFY:  rejected Lcom/twocell/walkabout/Animator;.overrideTransition (Landroid/content/Context;)V
07-19 23:42:29.150: WARN/dalvikvm(705): Verifier rejected class Lcom/twocell/walkabout/Animator;
07-19 23:42:29.160: DEBUG/AndroidRuntime(705): Shutting down VM
07-19 23:42:29.160: WARN/dalvikvm(705): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
07-19 23:42:29.160: ERROR/AndroidRuntime(705): Uncaught handler: thread main exiting due to uncaught exception
07-19 23:42:29.160: ERROR/AndroidRuntime(705): java.lang.VerifyError: com.twocell.walkabout.Animator
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at com.twocell.walkabout.Main.onCreate(SourceFile:199)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.os.Looper.loop(Looper.java:123)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at android.app.ActivityThread.main(ActivityThread.java:4203)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at java.lang.reflect.Method.invokeNative(Native Method)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at java.lang.reflect.Method.invoke(Method.java:521)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
07-19 23:42:29.160: ERROR/AndroidRuntime(705):     at dalvik.system.NativeStart.main(Native Method)

就这样-当我使用proguard时,只有在x10上,它仍然可以看到overridePendingTransition和崩溃。(我确认x10/is/reporting“4”是它的api版本。)
最后,my proguard.cfg:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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.android.vending.billing.**

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

#ACRA specifics
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this...
-keepattributes *Annotation*

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
        *;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
   *;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public void addCustomData(java.lang.String,java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public org.acra.ErrorReporter$ReportsSenderWorker   handleSilentException(java.lang.Throwable);
}

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

有什么想法吗?
编辑2
使用proguard中的-dontoptimize可以让应用程序在x10上运行。我在偷偷地想办法。

最佳答案

proguard的优化步骤将内联方法,如versionhelper overridetransition(),这不是您想要的,因为该方法旨在隔离对1.6的依赖关系(尽管proguard不知道这一点)。
暴力解决方案:关闭所有优化:

-dontoptimize

细粒度:关闭所有方法内联(正如您发现的那样):
-optimizations !method/inlining/*

理想解决方案:避免内联此特定方法及其同级:
-keepclassmembers,allowobfuscation,allowshrinking somepackage.VersionHelper {
  <methods>;
}

如果没有细节,我就不能多谈其他问题。你可以在Proguard的帮助论坛上提问。

10-08 13:19