我有一个应用程序,每天下载量超过5000次,并且每天有500多个用户处于活动状态,我无处不在开始出现关于Crashlytics的奇怪错误:
Caused by android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v24/ic_tickets.xml from drawable resource ID #0x7f0700b3
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2748)
at android.content.res.Resources.loadDrawable(Resources.java:2643)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.widget.TextView.<init>(TextView.java:921)
at android.widget.TextView.<init>(TextView.java:703)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:76)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:72)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
Caused by android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v24/$ic_tickets__0.xml from color state list resource ID #0x7f070017
at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2858)
at android.content.res.Resources.loadColorStateList(Resources.java:2807)
at android.content.res.TypedArray.getColor(TypedArray.java:439)
at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1605)
at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1584)
at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:666)
at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:571)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1215)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1124)
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #6: invalid color state list tag gradient
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:217)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:201)
at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2854)
at android.content.res.Resources.loadColorStateList(Resources.java:2807)
at android.content.res.TypedArray.getColor(TypedArray.java:439)
at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1605)
堆栈跟踪比这更长,在Crashlytics上有500多行,我在这里粘贴了我认为对理解问题可能有用的内容。
如果我做对了,它会抱怨我的资源之一丢失或损坏;会是什么?
但是该资源在apk中是完整的:
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:pathData="M381.845,292.27c0,11.032 -8.943,19.975 -19.975,19.975s-19.975,-8.943 -19.975,-19.975c0,-11.032 8.943,-19.975 19.975,-19.975S381.845,281.238 381.845,292.27zM361.869,332.221c-11.032,0 -19.975,8.943 -19.975,19.975s8.943,19.975 19.975,19.975s19.975,-8.943 19.975,-19.975S372.902,332.221 361.869,332.221zM361.869,392.147c-11.032,0 -19.975,8.943 -19.975,19.975s8.943,19.975 19.975,19.975s19.975,-8.943 19.975,-19.975S372.902,392.147 361.869,392.147zM307.418,136.36c-9.983,4.696 -14.268,16.596 -9.572,26.578c4.696,9.983 16.596,14.268 26.578,9.572c9.983,-4.696 14.268,-16.596 9.572,-26.578C329.3,135.95 317.401,131.664 307.418,136.36zM451.759,352.197c0,22.029 17.922,39.951 39.951,39.951h19.975V512H0.314V392.147H20.29c22.029,0 39.951,-17.922 39.951,-39.951s-17.922,-39.951 -39.951,-39.951H0.314V192.393h0.509l-0.042,-0.089L408.489,0l50.866,108.128l-17.013,8.861c-13.29,6.921 -21.544,20.506 -21.544,35.453c0,22.029 17.922,39.951 39.951,39.951h50.937v119.853H491.71C469.681,312.246 451.759,330.168 451.759,352.197zM94.244,192.393h297.352c-6.822,-11.763 -10.75,-25.403 -10.75,-39.951c0,-23.307 10.023,-44.953 27.021,-59.913l-18.505,-39.335l-81.134,38.269c4.355,9.886 0.068,21.491 -9.762,26.115c-9.818,4.618 -21.473,0.536 -26.323,-9.095L94.244,192.393zM411.808,352.197c0,-37.163 25.503,-68.482 59.926,-77.374v-42.479h-89.889c0,11.032 -8.943,19.975 -19.975,19.975s-19.975,-8.943 -19.975,-19.975H40.265v42.479c34.424,8.891 59.926,40.211 59.926,77.374s-25.503,68.482 -59.926,77.374v42.479h301.629c0,-11.032 8.943,-19.975 19.975,-19.975s19.975,8.943 19.975,19.975h89.889V429.57C437.31,420.678 411.808,389.36 411.808,352.197z">
<aapt:attr name="android:fillColor">
<gradient android:endX="256.00745" android:endY="511.99982"
android:startX="256.00745"
android:startY="-0.0150070675" android:type="linear">
<item android:color="#FF2AF598" android:offset="0"/>
<item android:color="#FF009EFD" android:offset="1"/>
</gradient>
</aapt:attr>
</path>
</vector>
drawable是应用程序中按钮的一个非常小而简单的图标,我从一个打开的图标库中下载了它,并在所有测试中都可以正常运行。
第二个奇怪的事情是,我今天有超过500个活跃用户,只有4个使用相同智能手机的用户才发生这种情况:
Device
Brand: LGE
Model: LG K10 LTE
Orientation: Portrait
RAM free: 170.92 MB
Disk free: 574.64 MB
Operating System
Version: 6.0
Orientation: Portrait
Rooted: No
Crash
此智能手机型号是否存在已知问题?我该怎么做才能为受影响的用户解决此问题?
答案 0 :(得分:3)
这是因为您使用了API级别[1, 3, 4, 5, 6, 121, 45]
之前不支持的一些属性。
例如24
,startX
,endX
,startY
和endY
。
Android棉花糖offset
是API级别6.0
...
23
来自invalid color state list tag gradient
:
offset
此问题很可能不是特定于<item android:color="#FF2AF598" android:offset="0"/>
<item android:color="#FF009EFD" android:offset="1"/>
,而是特定于LG
。
答案 1 :(得分:3)
在app:srcCompact
上使用src
代替ImageView
在您的build.gradle(app)
中编写以下代码:-
android.defaultConfig.vectorDrawables.useSupportLibrary = true
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
}
现在您可以看到它了。
答案 2 :(得分:1)
实际的问题是您定义的属性像android:fillColor
它应该是单一值的颜色,而不是渐变或颜色列表之类的颜色列表。它可以从API 24使用。我的建议是告诉您的设计师为24以下的API创建确切的徽标
答案 3 :(得分:0)
代替使用.xml设置图像资源,只需从Java代码中以编程方式设置图像资源即可。