【问题标题】:Vector image throwing android.content.res.Resources$NotFoundException in some devices在某些设备中抛出 android.content.res.Resources$NotFoundException 的矢量图像
【发布时间】:2019-02-18 02:09:16
【问题描述】:

我在一种布局中使用矢量图像 (svg) 作为背景。我用菜单添加了它

File -> New -> Vector Asset... 

我将它作为 .xml 放在我的可绘制文件夹中。

当我生成 .apk 文件并安装应用程序时,当我转到具有此布局且此图像作为背景的屏幕时,它会在某些设备中使应用程序崩溃,并引发错误

android.content.res.Resources$NotFoundException. 

但是,在其他设备中它可以完美运行。例如,它适用于 Android 版本 7.1.1,但会在版本 8 中崩溃。

我知道它可能会在具有 Lollipop (5.0) 之前的 Android 版本的设备中崩溃,但我只测试 6.0 及更高版本。

有人遇到过这个问题吗?

提前致谢。

【问题讨论】:

  • 但我没有在 5.0 之前的任何设备中安装该应用程序。我只是不明白为什么相同的 apk 在 7.1.1 中有效,但在 8.0 设备中无效。
  • 你是如何生成apk的?您使用的是“运行”还是“构建 -> 构建 APK”?它们产生不同的结果。 “运行”将生成一个 apk,它只有在您当前的调试设备/模拟器上运行所需的资源等。 “Build -> Build APK”将生成一个可以在符合清单中规范的任何设备上运行的 apk。
  • 嗨。如果我从 Android Studio“运行”该应用程序,它将在我连接的某些设备上运行,但在其他设备上则不行。都比棒棒糖高。同样,当我创建签名的 .apk 时,某些设备会抛出错误 Resource$NotFoundExcepcion,而另一种设备则可以正常工作。我以前在我的应用程序的更多屏幕中使用过矢量图像,并且它在所有设备中都运行良好。这个 SVG 似乎有问题。但我看到的唯一不同是这个有颜色渐变。

标签: android image svg vector android-vectordrawable


【解决方案1】:

这不是您要寻找的答案,但是当您使用 SVG 时,也许它就是您想要的 https://github.com/MegatronKing/SVG-Android

关于

SVG-Android 是一个支持库,用于在 android 4.0+ 中显示 svg 图像。

faster than png, vector and iconfont, the decoding stage costs less time.
better performance and expression than png even using a huge image.
support tint, alpha, size, selector whether in java code or xml code.
shrink the apk size, it can reduce the image size obviously.
support drawable animtions with some assigned animators.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    相关资源
    最近更新 更多