【问题标题】:VerifyError when using Instant Run使用即时运行时的验证错误
【发布时间】:2016-08-04 06:58:30
【问题描述】:

当达到XpInsetDrawable.create(Drawable, int)(下面的代码)时,会抛出VerifyError。当使用 Instant Run 时,不会发生这种情况。

我正在使用 Android Studio 2.0.0 和 gradle build plugin 2.0.0。在 SDK 22 上测试。在 SDK 19 模拟器上运行时,整个模拟器会重新启动。

我正在寻找“禁用 Instant Run”以外的解决方案。

异常(整个堆栈跟踪无关)

Caused by: java.lang.VerifyError:
Verifier rejected class net.xpece.android.support.preference.XpInsetDrawable due to bad method
java.lang.Object net.xpece.android.support.preference.XpInsetDrawable.access$super(
    net.xpece.android.support.preference.XpInsetDrawable,
    java.lang.String,
    java.lang.Object[])
(declaration of 'net.xpece.android.support.preference.XpInsetDrawable'
appears in /data/data/net.xpece.android.support.preference.sample/files/instant-run/dex/slice-slice_7-classe

类源代码

final class XpInsetDrawable extends InsetDrawable {
    private static final boolean NEEDS_FIXING = Build.VERSION.SDK_INT < 21;

    private final Rect mInset = new Rect();

    public static InsetDrawable create(final Drawable drawable, final int insetLeft, final int insetTop, final int insetRight, final int insetBottom) {
        if (NEEDS_FIXING) {
            return new XpInsetDrawable(drawable, insetLeft, insetTop, insetRight, insetBottom);
        } else {
            return new InsetDrawable(drawable, insetLeft, insetTop, insetRight, insetBottom);
        }
    }

    public static InsetDrawable create(final Drawable drawable, final int inset) {
        if (NEEDS_FIXING) {
            return new XpInsetDrawable(drawable, inset);
        } else {
            return new InsetDrawable(drawable, inset);
        }
    }

    XpInsetDrawable(final Drawable drawable, final int inset) {
        super(drawable, inset);
        mInset.set(inset, inset, inset, inset);
    }

    XpInsetDrawable(final Drawable drawable, final int insetLeft, final int insetTop, final int insetRight, final int insetBottom) {
        super(drawable, insetLeft, insetTop, insetRight, insetBottom);
        mInset.set(insetLeft, insetTop, insetRight, insetBottom);
    }

    @Override
    public int getIntrinsicHeight() {
        return super.getIntrinsicHeight() + mInset.top + mInset.bottom;
    }

    @Override
    public int getIntrinsicWidth() {
        return super.getIntrinsicWidth() + mInset.left + mInset.right;
    }
}

【问题讨论】:

标签: android instant-run


【解决方案1】:

2016-08-25 更新:在 Android Studio 2.2-beta3 中发布了修复。


2016-07-15 更新:修复的目标版本现在是 Android Studio 2.3。


我向 Android 提交了一个错误,这是 dev j...@google.com 不得不说的:

有趣!

XpInsetDrawable 是 InsetDrawable 的子类,它的父级在 23 年发生了变化。从 23 年开始,InsetDrawable 继承了 23 年添加的 DrawableWrapper。该应用程序使用 CompileSdkVersion 23 编译,因此我们为 DrawableWrapper 方法生成方法访问。

现在在

目前的解决方法是将 compileSdkVersion 设置为较低版本或在 InstantRun 模式下在 23 上运行应用程序。

潜在的解决方法是针对目标设备 API 级别 android.jar 而不是 compileSdkVersion 进行检测。这对于 2.1 来说太涉及了,针对 2.2。

来源:https://code.google.com/p/android/issues/detail?id=206746


这意味着在 Android Studio 2.2 发布之前,我不能继承 InsetDrawable 并同时使用 Instant Run。

我会考虑将 SDK 22 InsetDrawable 直接复制到我的项目中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 2017-09-29
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多