Empty Vector Drawable 在运行时导致 ResourceNotFound 异常

Ser*_*m's 4 android runtimeexception android-resources android-vectordrawable

我不能使用空矢量 drawable 作为占位符:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:viewportWidth="164.891"
    android:viewportHeight="75.543"
    android:width="164.891dp"
    android:height="75.543dp"></vector>
Run Code Online (Sandbox Code Playgroud)

Android Studio 没有指出 Activity 预览中的任何渲染问题,但在运行时我得到了这个致命的异常:

Caused by: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class ImageView
     Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class ImageView
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.xxxx.yyyy:drawable/product_logo_image with resource ID #0x7f080121
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/product_logo_image.xml from drawable resource ID #0x7f080121
Run Code Online (Sandbox Code Playgroud)

Man*_*ddy 6

更新

您的矢量中没有路径,添加不绘制任何内容的路径应该可以修复错误

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="dp"
    android:height="1dp"
    android:viewportWidth="1"
    android:viewportHeight="1">

  <path
      android:pathData="M0,0Z"
      android:fillColor="#ffffff"/>

</vector>
Run Code Online (Sandbox Code Playgroud)

  • 馊主意。这导致使用 AndroidX 在 Android 5.1 上崩溃:`java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.core.content.res.ComplexColorCompat.isStateful()' on a null object reference` (2认同)