【问题标题】:Android Studio verify error running on API < 17Android Studio 验证在 API < 17 上运行的错误
【发布时间】:2026-01-27 01:15:01
【问题描述】:

我正在将一个应用程序从 Eclipse 移植到 Android Studio,并在尝试在 API 小于 17 的模拟器上运行该应用程序时遇到验证错误。我将不胜感激有关如何处理此问题的任何指导。以下是 API 8 模拟器上 logcat 中显示的内容:

12-27 01:48:27.189 431-431/com.zigzagworld.icjl.tanachbible W/dalvikvm: VFY: register1 v10 type 12, wanted 10
12-27 01:48:27.189 431-431/com.zigzagworld.icjl.tanachbible W/dalvikvm: VFY:  rejecting opcode 0x70 at 0x005e
12-27 01:48:27.189 431-431/com.zigzagworld.icjl.tanachbible W/dalvikvm: VFY:  rejected Lcom/zigzagworld/fonts/GlyphMetrics;.<init> (SSS[S)V
12-27 01:48:27.189 431-431/com.zigzagworld.icjl.tanachbible W/dalvikvm: Verifier rejected class Lcom/zigzagworld/fonts/GlyphMetrics;

紧随其后的是应用程序崩溃并显示java.lang.VerifyError。相同的 .apk 文件将在 API 级别 17 及更高级别上运行良好。 API 17 及更高版本有不同的代码路径,但无论 API 级别如何,都会在某些时候使用 GlyphMetrics 类。 (如果不同的代码路径会影响一个类在加载时是否产生验证错误,请告诉我!)

GlyphMetrics 类是一个非常简单的容器,用于存储有关我们在应用中使用的自制位图字体的一些度量信息:

package com.zigzagworld.fonts;

import static com.zigzagworld.fonts.Diacritics.LOWER_DIACRITIC;
import static com.zigzagworld.fonts.Diacritics.UPPER_DIACRITIC;

/**
 * Represents the layout metrics for a glyph.
 * 
 * @author Ted Hopp
 */
public final class GlyphMetrics {

    public static final short[] EMPTY_EXCLUSION = new short[0];
    public static final short[][] EMPTY_EXCLUSIONS = { EMPTY_EXCLUSION, EMPTY_EXCLUSION };
    /** The width of the glyph image, in pixels. */
    public short width;
    /** The height of the glyph image, in pixels. */
    public short height;
    /**
     * The distance in pixels between the top of the glyph image and the
     * baseline of the line. A positive value means that the top of the glyph
     * should be above the baseline of the line; a negative value means that the
     * top of the glyph should be below the baseline of the line.
     */
    public short baseline;
    /**
     * The upper and lower axes for placement of diacriticals. Each axis is the
     * distance from the left of the glyph image at which diacriticals should be
     * centered. (The formatting algorithm for the font may move diacriticals
     * from this position to avoid interference between glyphs.)
     */
    public short[] axes;
    /**
     * The upper and lower exclusion zone arrays. If there are <i>n</i> upper
     * (say) zones, the upper array has length length 2*<i>n</i>. The array has
     * the left edge of the first zone, the right edge of the first zone, the
     * left edge of the second zone, etc. The lower zone data are organized in
     * the same way.
     */
    public short[][] zones;

    public GlyphMetrics(short width, short height, short baseline, short[] layoutData) {
        this.width = width;
        this.height = height;
        this.baseline = baseline;
        axes = new short[2];
        width >>= 1; // for the rest of this, we need the half-width
        if (layoutData == null || layoutData.length == 0) {
            axes[UPPER_DIACRITIC] = axes[LOWER_DIACRITIC] = width;
            zones = EMPTY_EXCLUSIONS;
        } else {
            axes[UPPER_DIACRITIC] = layoutData[0];
            if (layoutData.length < 2) {
                axes[LOWER_DIACRITIC] = width;
            } else {
                axes[LOWER_DIACRITIC] = layoutData[1];
            }
            if (layoutData.length < 5) {
                zones = EMPTY_EXCLUSIONS;
            } else {
                int nUpper = layoutData[2] << 1;
                zones = new short[2][];
                zones[UPPER_DIACRITIC] = new short[nUpper];
                System.arraycopy(layoutData, 3, zones[UPPER_DIACRITIC], 0, nUpper);

                int lowerStart = 3 + nUpper;
                if (layoutData.length < 2 + lowerStart) {
                    zones[LOWER_DIACRITIC] = EMPTY_EXCLUSION;
                } else {
                    int nLower = layoutData[lowerStart++] << 1;
                    zones[LOWER_DIACRITIC] = new short[nLower];
                    System.arraycopy(layoutData, lowerStart, zones[LOWER_DIACRITIC], 0, nLower);
                }
            }
        }
    }
}

(导入 UPPER_DIACRITICLOWER_DIACRITIC 分别是常量 0 和 1。)

我正在使用带有 Gradle 插件 com.android.tools.build:gradle:2.0.0-alpha3 和 JDK 1.7.0_80 的 Android Studio 2.0 Preview 4 构建它。这是 .apk 模块的build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        applicationId "com.zigzagworld.icjl.tanachbible"
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 10800310
        versionName "3.1.0"
        manifestPlaceholders = [
                appName: "App",
                v8TOCActivityName: "BaseTOCActivity",
                v8PurchaseActivityName: "PurchaseActivity",
                v17TOCActivityName: "TOCActivity",
                v17PurchaseActivityName: "PurchaseActivity",
        ]
    }
    signingConfigs {
        // redacted for this post
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //noinspection GroovyAssignabilityCheck
            signingConfig // redacted
        }
    }
    flavorDimensions "market"
    productFlavors {
        google {
            dimension "market"
            manifestPlaceholders = [
                appName: "App_Google",
                v8TOCActivityName: "TOCActivity_Google",
                v8PurchaseActivityName: "GooglePurchaseActivity",
                v17TOCActivityName: "TOCActivity_Google",
                v17PurchaseActivityName: "GooglePurchaseActivity"
            ]
        }
        amazon {
            dimension "market"
            manifestPlaceholders = [
                appName: "App_Amazon",
                v8TOCActivityName: "BaseTOCActivity",
                v8PurchaseActivityName: "PurchaseActivity",
                v17TOCActivityName: "TOCActivity",
                v17PurchaseActivityName: "PurchaseActivity"
            ]
        }
        sideLoad {
            dimension "market"
            manifestPlaceholders = [
                    appName: "App_Unlicensed",
                    v8TOCActivityName: "BaseTOCActivity",
                    v8PurchaseActivityName: "PurchaseActivity",
                    v17TOCActivityName: "TOCActivity",
                    v17PurchaseActivityName: "PurchaseActivity"
            ]
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-annotations:23.1.1'
    compile project(':Tanach Data')
    googleCompile project(':Google Vending')
    amazonCompile project(':Amazon Vending')
}

问题出现在调试构建类型上,因此 ProGuard 目前不在图片中。

【问题讨论】:

  • 也许这个链接的答案可能会有所帮助,这是我第一次看到 VerifyError 所以我想我想帮助*.com/questions/100107/…
  • @JRowan - 我没有看到那个特定的链接,但我确实看到了许多类似的链接。那里没有我没有尝试过的东西(清理项目,在 build.gradle 的 compileOptions 块中添加 sourceCompatibility JavaVersion.VERSION_1_7targetCompatibility JavaVersion.VERSION_1_7,检查库版本,重新启动 IDE 等)无论如何,谢谢。跨度>
  • 哦,我只是想把它放上去我还在使用 eclipse,还没有切换到 android studio 但我想,因为它仍然相对较新,也许它是 ide,甚至不是编程错误,抱歉它不是一个可靠的领先优势:(
  • 我注意到你有 com.zigzagworld.fonts;你有 com.zigzagworld.icjl.tanachbible”,其中一个是图书馆吗?
  • 在花了几天时间之后,我刚刚发现将 gradle 插件从 2.0.0-alpha3 降级到 1.5.0 会使问题消失。

标签: java android eclipse verifyerror android-studio-2.0


【解决方案1】:

花了几天的时间后,我才发现将 gradle 插件从 2.0.0-alpha3 降级到 1.5.0 会使问题消失。

这是我们为保持领先而付出的代价。

【讨论】:

  • 谢谢!我想是全额支付的价格。 :-/
最近更新 更多