应用程序在 Android 10 上崩溃布局/abc_screen_simple 行 #17 中的 InflateException

问题描述

好的开始,我在这里尝试了所有其他答案(一些示例herehere),以至于我什至转到了 Google 搜索的第 5 页。

问题

当我设置 targetSdkVersion <= 28 时,我的应用程序运行良好,但如果我将其设置为更高的值 (29,30),Android 10 设备的应用程序会在启动时崩溃。我没有任何书法库,我的文件中没有任何 abc_screen_simple 布局。非常感谢任何帮助。

Logcat(更新)

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/telegram.free.sticker.MainActivity}: android.view.InflateException: Binary XML file line #17 in com.example.app:layout/abc_screen_simple: Binary XML file line #17 in com.example.app:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitwindowsLinearLayout
        at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:3654)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
        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:2267)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
     Caused by: android.view.InflateException: Binary XML file line #17 in com.example.app:layout/abc_screen_simple: Binary XML file line #17 in com.example.app:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitwindowsLinearLayout
     Caused by: android.view.InflateException: Binary XML file line #17 in com.example.app: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 com.asha.nightowllib.inflater.InjectedInflaterBase.getConstructorArgs(InjectedInflaterBase.java:81)
        at com.asha.nightowllib.inflater.LastChance2Inflater.lastChance2CreateView(LastChance2Inflater.java:22)
        at com.asha.nightowllib.inflater.InjectedInflaterV11$PrivateFactoryWrapperImpl.onCreateView(InjectedInflaterV11.java:189)
        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 android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:920)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
        at telegram.free.sticker.MainActivity.onCreate(MainActivity.java:52)
        at android.app.Activity.performCreate(Activity.java:7963)
        at android.app.Activity.performCreate(Activity.java:7952)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:3629)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
        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:2267)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
2021-01-22 17:16:26.209 24854-24854/com.signalmeme.stickers E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

我的activity_main.xml

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

我的 build.gradle

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
}

android {
    compileSdkVersion 30
    buildToolsversion "28.0.3"

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment:2.3.2'
    implementation 'androidx.navigation:navigation-ui:2.3.2'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'com.facebook.android:audience-network-sdk:6.2.0'
    implementation 'com.asha.nightowllib:nightowllib:0.2'
    implementation 'com.facebook.shimmer:shimmer:0.5.0'

    //Firebase
    implementation platform('com.google.firebase:firebase-bom:26.2.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-inappmessaging-display'
    implementation 'com.google.firebase:firebase-crashlytics'

}

解决方法

多亏了@CommonsWare comment,我才能通过删除来解决这个问题

implementation 'com.asha.nightowllib:nightowllib:0.2'

由于某种原因,这个库是应用在 Android 10 设备上崩溃的原因。

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 com.asha.nightowllib.inflater.InjectedInflaterBase.getConstructorArgs(InjectedInflaterBase.java:81)
        at com.asha.nightowllib.inflater.LastChance2Inflater.lastChance2CreateView(LastChance2Inflater.java:22)
        at com.asha.nightowllib.inflater.InjectedInflaterV11$PrivateFactoryWrapperImpl.onCreateView(InjectedInflaterV11.java:189)

对于将来可能发生类似崩溃的任何人,请查看您的堆栈跟踪以查找对您添加的库的任何引用,这可能是罪魁祸首。