Skip to content

Commit 546ca10

Browse files
Material Design Teamdsn5ft
authored andcommitted
[Drawable] Resolve class verification issues for DrawableUtils
Post appreduce, a lot of DrawableUtils methods are horizontally merged into other classes. Since these methods are not available on older Android platform versions, ART instructs the runtime to re-verify when the app loads. When one of these methods is present in a very large horizontally merged class, it can take a lot of time to verify. On Pixel 2XL for Android Q, I have seen 12-15ms being very common. Related docs and see linked bug: https://chromium.googlesource.com/chromium/src/+/HEAD/build/android/docs/class_verification_failures.md#understanding-the-reason-for-the-failure PiperOrigin-RevId: 605643227
1 parent 3560672 commit 546ca10

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/java/com/google/android/material/drawable/DrawableUtils.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.android.material.drawable;
1818

19+
import com.google.android.material.R;
20+
1921
import static java.lang.Math.max;
2022

2123
import android.annotation.SuppressLint;
@@ -41,9 +43,11 @@
4143
import android.util.Xml;
4244
import android.view.Gravity;
4345
import androidx.annotation.ColorInt;
46+
import androidx.annotation.DoNotInline;
4447
import androidx.annotation.NonNull;
4548
import androidx.annotation.Nullable;
4649
import androidx.annotation.Px;
50+
import androidx.annotation.RequiresApi;
4751
import androidx.annotation.RestrictTo;
4852
import androidx.annotation.RestrictTo.Scope;
4953
import androidx.annotation.XmlRes;
@@ -359,18 +363,18 @@ public static int[] getUncheckedState(@NonNull int[] state) {
359363
/** Sets the Outline to a {@link android.graphics.Path path}, if possible. */
360364
public static void setOutlineToPath(@NonNull final Outline outline, @NonNull final Path path) {
361365
if (VERSION.SDK_INT >= VERSION_CODES.R) {
362-
outline.setPath(path);
366+
OutlineCompatR.setPath(outline, path);
363367
} else if (VERSION.SDK_INT >= VERSION_CODES.Q) {
364368
try {
365369
// As of Android Q, the restriction that the path must be convex is removed, but the API is
366370
// misnamed until the introduction of setPath() in R, so we have to use setConvexPath for Q.
367-
outline.setConvexPath(path);
371+
OutlineCompatL.setConvexPath(outline, path);
368372
} catch (IllegalArgumentException ignored) {
369373
// The change to support concave paths was done late in the release cycle. People
370374
// using pre-releases of Q would experience a crash here.
371375
}
372376
} else if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && path.isConvex()) {
373-
outline.setConvexPath(path);
377+
OutlineCompatL.setConvexPath(outline, path);
374378
}
375379
}
376380

@@ -401,4 +405,22 @@ public static ColorStateList getColorStateListOrNull(@Nullable final Drawable dr
401405

402406
return null;
403407
}
408+
409+
@RequiresApi(VERSION_CODES.R)
410+
private static class OutlineCompatR {
411+
// Avoid class verification failures on older Android versions.
412+
@DoNotInline
413+
static void setPath(@NonNull Outline outline, @NonNull Path path) {
414+
outline.setPath(path);
415+
}
416+
}
417+
418+
@RequiresApi(VERSION_CODES.LOLLIPOP)
419+
private static class OutlineCompatL {
420+
// Avoid class verification failures on older Android versions.
421+
@DoNotInline
422+
static void setConvexPath(@NonNull Outline outline, @NonNull Path path) {
423+
outline.setConvexPath(path);
424+
}
425+
}
404426
}

0 commit comments

Comments
 (0)