VerifyError when using Instant Run

A VerifyError is thrown when XpInsetDrawable.create(Drawable, int) reached (code below). This does not happen if you do not use Instant Run.

I am using Android Studio 2.0.0 and gradle build plugin 2.0.0. Tested on SDK 22. When launched on the SDK 19 emulator, the entire emulator reboots.

I am looking for a solution other than "disable Instant Run".

Exception (whole stack trace is not bound)

 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 

Class source code

 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; } } 
+5
source share
1 answer

UPDATE 2016-08-25: Patch released in Android Studio 2.2-beta3.


UPDATE 2016-07-15: The target release for the fix is ​​now Android Studio 2.3.


I filed an error with Android, and here is what dev j said ... @ google.com :

Interesting!

XpInsetDrawable is a subclass of InsetDrawable whose parent has changed to 23. Starting at 23, InsetDrawable is a subclass of DrawableWrapper that was added at 23. The application is compiled with CompileSdkVersion 23, so we generate calls to DrawableWrapper methods.

now when starting at <23 these methods do not exist, in fact the class does not exist, so we explode.

Workaround

is to compile SDkVersion into a lower version or run application 23 in InstantRun mode.

and

A potential fix is ​​a tool against the target level of the android.jar API, not for compileSdkVersion. This is too related to 2.1, oriented to 2.2.

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


This means that I cannot subclass InsetDrawable and use Instant Run at the same time until Android Studio 2.2 is released.

I will consider copying SDK 22 InsetDrawable directly to my project.

+2
source

Source: https://habr.com/ru/post/1247024/


All Articles