3

我正在为 minSDK 8 和 targetSDK 11 构建。

<uses-sdk android:minSdkVersion="8"
          android:targetSdkVersion="11"/>

我在logcat中得到这个:

WARN/dalvikvm(2114): VFY:  rejected Lcom/examplecompany/project/TidalStreams/Data/gTidalStreamsHourlyHW;.<clinit> ()V

WARN/dalvikvm(2114): Verifier rejected class Lcom/digitaliridium/tides/TidalStreams/Data/gTidalStreamsHourlyHW;

在其他几个设备中,我有两个欲望;一个运行 2.2.2,一个运行 2.3.3。

在 2.2.2 上,我java.lang.VerifyError在这一行得到一个:

public void onCreate(){
    ...

    gTidalStreamsHourlyHW.init();

    ...
}

这里是init()方法。这是一个非常普通的类的唯一方法。

public static void init(){


    int insertPosition;
    System.arraycopy(gTidalStreamHourlyHW1, 0,  gTidalStreamHourlyHW, 0, gTidalStreamHourlyHW1.length);

    insertPosition = gTidalStreamHourlyHW1.length;
    System.arraycopy(gTidalStreamsHourlyHW2.gTidalStreamHourlyHW1, 0,  gTidalStreamHourlyHW, insertPosition, gTidalStreamsHourlyHW2.gTidalStreamHourlyHW1.length);

    insertPosition += gTidalStreamsHourlyHW2.gTidalStreamHourlyHW1.length;
    System.arraycopy(gTidalStreamsHourlyHW3.gTidalStreamHourlyHW1, 0,  gTidalStreamHourlyHW, insertPosition, gTidalStreamsHourlyHW3.gTidalStreamHourlyHW1.length);

    ...

gTidalStreamsHourlyHW是一个大数据数组,大约 350k。我不得不将它拆分为多个文件以绕过 Java 的 64k 编译单元限制。

init方法简单地使用 System.arraycopy() 将这些多个静态数组连接成一个。

我尝试将 minSDK 级别降低到 7,但问题是一样的。

它在运行 2.2.2 的模拟器中也失败了。

4

1 回答 1

3

我是 Android 的忠实粉丝,但有时它是站不住脚的 :(

错误中有一条线索表明该错误与静态初始化程序有关;这是<clinit>“方法”名称:

WARN/dalvikvm(2114): VFY:  rejected Lcom/examplecompany/project/TidalStreams/Data/gTidalStreamsHourlyHW;.<clinit> ()V

这表明错误可能与static { ... }初始化程序块或某些static类成员的初始化有关。

我的班级有一个静态数组初始化程序:

 public static shcTidalStreamPointStruct[] gTidalStreamHourlyHW1  = new shcTidalStreamPointStruct[]{

            new shcTidalStreamPointStruct("000A",48.766667,-10.066667,51.116667,1.316667,"89",95,0.8,0.4,125,0.9,0.4,172,0.7,0.4,216,0.7,0.4,242,0.8,0.4,261,0.9,0.4,281,0.7,0.4,305,0.7,0.4,339,0.6,0.3,14,0.6,0.3,58,0.6,0.3,71,0.7,0.3,91,0.7,0.4,"GB",0),
            new shcTidalStreamPointStruct("000B",49.533333,-9.983333,51.116667,1.316667,"89",122,0.6,0.3,166,0.8,0.4,192,0.9,0.4,213,0.9,0.5,239,0.9,0.5,255,0.9,0.5,286,0.9,0.4,330,0.7,0.4,9,0.9,0.4,38,1,0.5,52,1.1,0.5,68,0.9,0.5,104,0.6,0.3,"GB",0),
            new shcTidalStreamPointStruct("000C",48.898333,-9.163333,51.116667,1.316667,"89",102,0.4,0.2,118,0.6,0.3,172,0.7,0.4,197,0.7,0.4,212,0.7,0.4,250,0.7,0.4,283,0.5,0.3,321,0.3,0.2,337,0.5,0.3,13,0.7,0.4,33,0.7,0.4,54,0.5,0.3,98,0.4,0.2,"GB",0),

有 283 个元素。

我仅使用此代码构建了一个测试项目,并验证了在 2.2 及以下版本中,它失败了。在 2.3 及更高版本上,它可以工作。

问题是初始化程序中的行数!我一次取出一条线,直到剩下 197 条线并且它有效!

除了 Java 的 64k 编译单元限制之外,Android 类加载器中还有一些与静态初始化的行数/大小相关的未记录限制(或错误)。

解决方法是进一步拆分我的文件以减少行数。胡说八道....

于 2013-03-31T17:45:43.083 回答