【问题标题】:Android ResourcesNotFoundException on first App start首次应用启动时出现 Android ResourcesNotFoundException
【发布时间】:2021-06-06 05:09:17
【问题描述】:

每当我第一次运行该应用程序时,我都会收到以下异常

com.mypckg.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mypckg.myapp, PID: 6460
    android.content.res.Resources$NotFoundException: Resource ID #0x20c0016
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
        at android.content.res.Resources.getInteger(Resources.java:1127)
        at org.chromium.ui.base.DeviceFormFactor.isTablet(chromium-TrichromeWebViewGoogle.aab-stable-438907233:2)
        at Vm.a(chromium-TrichromeWebViewGoogle.aab-stable-438907233:2)
        at Lc.run(chromium-TrichromeWebViewGoogle.aab-stable-438907233:3)
        at org.chromium.content.browser.BrowserStartupControllerImpl.e(chromium-TrichromeWebViewGoogle.aab-stable-438907233:10)
        at org.chromium.content.browser.BrowserStartupControllerImpl.g(chromium-TrichromeWebViewGoogle.aab-stable-438907233:7)
        at t6.run(chromium-TrichromeWebViewGoogle.aab-stable-438907233:20)
        at org.chromium.base.ThreadUtils.f(chromium-TrichromeWebViewGoogle.aab-stable-438907233:2)
        at sp0.j(chromium-TrichromeWebViewGoogle.aab-stable-438907233:32)
        at rp0.run(chromium-TrichromeWebViewGoogle.aab-stable-438907233:2)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

然后当我第二次、第三次打开应用程序时,它就可以正常工作了。

我猜这可能是由于某些库,所以这是我的 app.gradle 文件

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
    

    compileSdkVersion 29
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.mypckg.myapp"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 16
        versionName "1.0.17"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        setProperty("archivesBaseName", "MyApp"+ versionName +"_"+new Date().format( 'yyyy-MM-dd HH:mm' ))
    }

    buildTypes {
        debug {
            buildConfigField "String", 'BASE_URL', '"https://baseurl.com/"'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            buildConfigField "String", 'BASE_URL', '"https://baseurl.com/"'
        }


    }
    viewBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

dependencies {
    def room_version = '2.2.6'
    def retrofitVersion = '2.8.1'
    def okhttpVersion = '4.5.0'
    def daggerVersion = '2.31.2'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.material:material:1.4.0-alpha01'
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-rxjava2:$room_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
    implementation 'androidx.fragment:fragment-ktx:1.3.0'

    implementation "com.github.doyaaaaaken:kotlin-csv-jvm:0.11.0"

    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation "com.google.dagger:dagger:$daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$daggerVersion"

    implementation "com.google.dagger:hilt-android:2.31.2-alpha"
    kapt "com.google.dagger:hilt-android-compiler:2.31.2-alpha"
    implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
    kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha03'

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'

    debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
    implementation 'com.github.quickpermissions:quickpermissions-kotlin:0.4.0'

    implementation 'com.facebook.android:audience-network-sdk:5.10.0'
    implementation platform('com.google.firebase:firebase-bom:26.6.0')
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation 'com.jakewharton.threetenabp:threetenabp:1.2.4'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}

这是我的项目级 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.31"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28-alpha'
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "http://jitpack.io/" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 根据堆栈跟踪,这不是您的代码问题。无论如何,您可以检查项目 R 文件是否包含资源 ID #0x20c0016。

标签: java android firebase kotlin kotlin-android-extensions


【解决方案1】:

我也有同样的问题, 由于我将 MobileAds.initialize 从 Application 类移动到另一个类。 您可以尝试在 Application 类中初始化 MobileAds.initialize

【讨论】:

    【解决方案2】:

    三星开发者论坛也提到了这个问题,但没有提供解决方案。见https://forum.developer.samsung.com/t/android-content-res-resources-notfoundexception-in-org-chromium-ui-base-deviceformfactor-istablet/17544/4

    关于这个问题有更多的信息吗?我也在我的应用程序中看到它。最初我只在搭载 Android 12 的三星 S21 手机上看到它,现在我还在一部搭载 Android 12 的 Pixel 3 手机和搭载 Android 11 的三星 S21 上获得了 Crashlytics 的崩溃报告……它最常发生在这次通话中:

    String uas = WebSettings.getDefaultUserAgent(context);
    

    怀疑只有在还没有创建 WebView 控件时调用它才会发生,因为到目前为止,当在其中创建控件时,我没有发现应用程序稍后的类似调用导致崩溃。用 try - catch 围绕这一行没有帮助,因为崩溃似乎发生在另一个线程中。

    格雷格

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 2021-09-04
      • 2013-02-04
      • 2020-07-30
      • 2022-11-05
      • 2016-07-18
      • 1970-01-01
      相关资源
      最近更新 更多