InflateException只是在发布模式下

时间:2017-11-11 11:43:29

标签: android

最近我用uk.co.chrisjenx.calligraphy库在我的观点上设置字体。在调试模式下,一切正常,但在发布模式下,通过单击任何活动,它具有InflateException。我需要一些帮助来处理它。 。 这是我的ProGuard规则:

    -keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

-dontwarn com.squareup.okhttp.**
-keep class android.**
-dontwarn android.**
-dontwarn com.google.android.gms.**

,这是Android Studio日志:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.matingdz.InsDLFreeGooglePlay, PID: 4592
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matingdz.InsDLFreeGooglePlay/com.matingdz.InsDLFreeGooglePlay.DlStory}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class Button
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                      at android.os.Handler.dispatchMessage(Handler.java:105)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                   Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class Button
                   Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class Button
                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.AppCompatBackgroundHelper.a()' on a null object reference
                      at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(Unknown Source:5)
                      at android.view.View.setBackground(View.java:20326)
                      at android.view.View.<init>(View.java:5200)
                      at android.widget.TextView.<init>(TextView.java:824)
                      at android.widget.Button.<init>(Button.java:172)
                      at android.widget.Button.<init>(Button.java:147)
                      at android.support.v7.widget.AppCompatButton.<init>(Unknown Source:4)
                      at android.support.v7.widget.AppCompatButton.<init>(Unknown Source:3)
                      at android.support.v7.app.AppCompatViewInflater.a(Unknown Source:284)
                      at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(Unknown Source:51)
                      at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(Unknown Source:4)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(Unknown Source:3)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                      at android.support.v7.app.AppCompatDelegateImplV9.b(Unknown Source:23)
                      at android.support.v7.app.AppCompatActivity.setContentView(Unknown Source:4)
                      at com.matingdz.InsDLFreeGooglePlay.DlStory.onCreate(Unknown Source:7)
                      at android.app.Activity.performCreate(Activity.java:6975)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)

1 个答案:

答案 0 :(得分:0)

尝试将此规则添加到Proguard规则文件中:

-keepclassmembernames class android.support.v7.widget.** { *; }

我不确定它是否是最佳解决方案,但它为我做了诀窍。