资源$ NotFoundException在proguard之后的自定义视图的致命异常,在特定设备上

时间:2017-01-16 09:45:02

标签: android android-custom-view android-resources android-proguard

我在几个特定设备上遇到崩溃的以下堆栈跟踪。我遇到崩溃的两个设备都在运行OSv5.1

Fatal Exception: android.view.InflateException: Binary XML file line #161: Error inflating class com.adroitandroid.stitchastory.ui.AppTextInputLayoutPlus
       at android.view.LayoutInflater.createView(LayoutInflater.java:633)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:116)
       at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:88)
       at com.adroitandroid.stitchastory.HomeActivity$StartStoryFragment.onCreateView(HomeActivity.java:415)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
       at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:709)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5763)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:607)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:116)
       at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:88)
       at com.adroitandroid.stitchastory.HomeActivity$StartStoryFragment.onCreateView(HomeActivity.java:415)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
       at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:709)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5763)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by android.content.res.Resources$NotFoundException: Resource ID #0x7f0f007c
       at android.content.res.Resources.getValue(Resources.java:1463)
       at android.support.v7.content.res.AppCompatResources.isColorInt(AppCompatResources.java:161)
       at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:108)
       at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:74)
       at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:136)
       at android.support.design.widget.TextInputLayout.(TextInputLayout.java:244)
       at android.support.design.widget.TextInputLayout.(TextInputLayout.java:183)
       at com.adroitandroid.stitchastory.ui.TextInputLayoutPlus.(TextInputLayoutPlus.java:19)
       at com.adroitandroid.stitchastory.ui.AppTextInputLayoutPlus.(AppTextInputLayoutPlus.java:16)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:607)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:116)
       at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:88)
       at com.adroitandroid.stitchastory.HomeActivity$StartStoryFragment.onCreateView(HomeActivity.java:415)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
       at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:709)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5763)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

提到的资源是

    public static final int design_tint_password_toggle=0x7f0f007c;

在我的R.java中,基本上不是我自己定义的资源。但是,这是一个自定义布局,我试图在这里膨胀。对于另一个此前的崩溃,我在xml中明确提到了我的视图中的文本颜色来修复它。但这是不同的,因为它是一个无法找到的android资源。这在推出应用程序时也不对。

要添加,这是一个程序设计的apk,我在我的proguard配置文件中有以下内容来保留常量。

-keepclassmembers class **.R$* {
    public static <fields>;
}
-keep class **.R$*

我也试过评论

shrinkResources true

对于特定的构建类型,但它没有解决这个问题。

我正在使用buildToolsVersion '25 .0.1'

支持库版本为25.1.0,here is the layout file它正在尝试在崩溃时膨胀。第161行是声明与崩溃相关的视图的位置。为方便起见,贴在这里。

<com.adroitandroid.stitchastory.ui.AppTextInputLayoutPlus
    android:id="@+id/contribution_til"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@id/done_ib"
    android:layout_alignStart="@id/cancel_ib"
    android:layout_below="@id/done_ib"
    android:layout_centerInParent="true"
    android:paddingTop="16dp"
    app:counterEnabled="true"
    app:counterMaxLength="@integer/maxContributionLength"
    app:errorEnabled="true"
    app:hintEnabled="false">

    <com.adroitandroid.stitchastory.ui.ContentEditTextPlus
        android:id="@+id/contribution_et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top"
        android:hint="@string/hint_add_story"
        android:imeOptions="actionDone"
        android:inputType="textAutoComplete|textCapSentences|textShortMessage|textMultiLine" />
</com.adroitandroid.stitchastory.ui.AppTextInputLayoutPlus>

对于AppTextInputLayoutPlus没什么好看的,它只是采用以下方式的自定义字体。

abstract class TextInputLayoutPlus extends TextInputLayout {
    public TextInputLayoutPlus(Context context) {
        super(context);
        init();
    }

    public TextInputLayoutPlus(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TextInputLayoutPlus(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setTypeface(Typeface.createFromAsset(getContext().getAssets(), getTextFont()));
    }

    protected abstract String getTextFont();
}
// in its own class file
public class AppTextInputLayoutPlus extends TextInputLayoutPlus {
    public AppTextInputLayoutPlus(Context context) {
        super(context);
    }

    public AppTextInputLayoutPlus(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AppTextInputLayoutPlus(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected String getTextFont() {
        return AppTextView.APP_TEXT_FONT;
    }
}

有没有人知道解决这个问题的方法,以及为什么会这样?

1 个答案:

答案 0 :(得分:0)

这是一个猜测 - 问题与TextInputLayout无关,但更多与ContentEditTextPlus有关。最近我在ContentEditTextPlus和其他类似的代码中发现了一个问题,其中我覆盖了一个setTextColor(),它混合了ColorInt的ColorRes int参数,反之亦然。这应该解释getColorStateList()中的资源未找到异常。