将项目更新到 android 10 后 onCreate 活动崩溃
Posted
技术标签:
【中文标题】将项目更新到 android 10 后 onCreate 活动崩溃【英文标题】:Crash in onCreate activity after update project to android 10 【发布时间】:2020-06-15 15:37:00 【问题描述】:将我的项目更新到 android 10 后,我的 HomeActivity 崩溃了,该应用程序在旧版本的 android 上运行良好,但是当我使用 Android 10 设备时发生崩溃,我有一个启动活动,它运行良好,但发生了崩溃在 onCreate setContentView(R.layout.activity_home);
上移动到主活动后这是崩溃报告:
E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfocom.aia.portercustomer/com.aia.portercustomer.activity.HomeActivity: android.view.InflateException: Binary XML file line #17 in com.aia.portercustomer:layout/abc_screen_simple: Binary XML file line #17 in com.aia.portercustomer:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: android.view.InflateException: Binary XML file line #17 in com.aia.portercustomer:layout/abc_screen_simple: Binary XML file line #17 in com.aia.portercustomer:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
Caused by: android.view.InflateException: Binary XML file line #17 in com.aia.portercustomer:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference
at uk.co.chrisjenx.calligraphy.ReflectionUtils.getValue(ReflectionUtils.java:29)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:203)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:239)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.inflate(LayoutInflater.java:659)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.aia.portercustomer.activity.HomeActivity.onCreate(HomeActivity.java:408)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1300)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
2020-03-03 11:26:24.019 17491-17491/com.aia.portercustomer E/UncaughtException: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
我还尝试了这个答案Android 10 Activity onCreate Crash 中提到的解决方案,方法是将这些依赖项添加到我的项目中
// Annotation processor
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha05"
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha05"
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0-alpha05"
implementation "androidx.lifecycle:lifecycle-process:2.2.0-alpha05"
implementation "androidx.lifecycle:lifecycle-service:2.2.0-alpha05"
但这没有帮助。
【问题讨论】:
【参考方案1】:查看崩溃日志:
Caused by: android.view.InflateException: Binary XML file line #17 in com.aia.portercustomer:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
在您的 app.gradle 中,添加以下内容:
implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'
阅读更多关于这个Issue
【讨论】:
【参考方案2】:崩溃似乎来自 Caligraphy 库。This issue 看起来就像您正在经历的那样。
【讨论】:
以上是关于将项目更新到 android 10 后 onCreate 活动崩溃的主要内容,如果未能解决你的问题,请参考以下文章
将 android 系统从 10 更新到 11 时 isExternalStorageLegacy 为 false
从 3.6 更新到 Android Studio 4.0 后构建具有 NDK 支持的项目时出错
将 android studio 更新到 4.2 Beta1 后,Gradle 构建失败
加载“旧”Android Studio 项目 - 在 Studio 更新后,它将不再打开/编译,要求更新版本?