Eug*_*nec 5 android instant-run
VerifyError当XpInsetDrawable.create(Drawable, int)达到(下面的代码)时抛出A. 不使用Instant Run 时不会发生这种情况.
我正在使用Android Studio 2.0.0和gradle build plugin 2.0.0.在SDK 22上测试.在SDK 19模拟器上运行时,整个模拟器重新启动.
我正在寻找除"禁用即时运行"之外的解决方案.
异常(整个堆栈跟踪无关)
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
Run Code Online (Sandbox Code Playgroud)
类源代码
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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 方法生成方法访问。
现在,当在 <23 上运行时,这些方法不存在,事实上该类不存在,所以我们爆炸了。
目前的解决方法是将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 22InsetDrawable直接复制到我的项目中。
| 归档时间: |
|
| 查看次数: |
891 次 |
| 最近记录: |