简体   繁体   English

第一次应用启动时 Android ResourcesNotFoundException

[英]Android ResourcesNotFoundException on first App start

Whenever I run the app for the first time, I get the following exception每当我第一次运行该应用程序时,我都会收到以下异常

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)

Then when I open the app for the second,third time, it works fine.然后当我第二次,第三次打开应用程序时,它工作正常。

I am guessing this might be due to some libraries, so here is my app.gradle file我猜这可能是由于某些库,所以这是我的 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'
}

and this is my project level build.gradle这是我的项目级别 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
}

Any help would be highly appreciated.任何帮助将不胜感激。 Thanks谢谢

I have the same issue, due I move MobileAds.initialize from the Application class to another class.我有同样的问题,因为我将 MobileAds.initialize 从应用程序 class 移动到另一个 class。 You can try to init MobileAds.initialize at Application class您可以尝试在 Application class 处初始化 MobileAds.initialize

In our App I see the same problem on Samsung Galaxy S21 in crashlytics (12 crashes in 7 day's )在我们的应用程序中,我在崩溃分析中看到三星 Galaxy S21 上的相同问题(7 天内 12 次崩溃)

Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x20c0025
   at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:240)
   at android.content.res.Resources.getInteger(Resources.java:1275)
   at org.chromium.ui.base.DeviceFormFactor.isTablet(:8)
   at cs.a(:4)
   at org.chromium.content.browser.BrowserStartupControllerImpl.e(:25)
   at org.chromium.content.browser.BrowserStartupControllerImpl.g(:26)
   at E8.run(:127)
   at org.chromium.base.ThreadUtils.f(:6)
   at EB0.g(:209)
   at DB0.run(:7)
   at android.os.Handler.handleCallback(Handler.java:938)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loopOnce(Looper.java:226)
   at android.os.Looper.loop(Looper.java:313)
   at android.app.ActivityThread.main(ActivityThread.java:8582)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)

This issue was also mentioned in Samsung Developer Forum, but no solution offered.三星开发者论坛也提到了这个问题,但没有提供解决方案。 See https://forum.developer.samsung.com/t/android-content-res-resources-notfoundexception-in-org-chromium-ui-base-deviceformfactor-istablet/17544/4请参阅https://forum.developer.samsung.com/t/android-content-res-resources-notfoundexception-in-org-chromium-ui-base-deviceformfactor-istablet/17544/4

Is there any more information on this issue?有没有关于这个问题的更多信息? I see it in my app too.我也在我的应用程序中看到它。 Initially I saw it ONLY on Samsung S21 phones with Android 12, now I got also a crash report on Crashlytics on one Pixel 3 phone with Android 12, and several on Samsung S21 with Android 11… It happens most often on this call: Initially I saw it ONLY on Samsung S21 phones with Android 12, now I got also a crash report on Crashlytics on one Pixel 3 phone with Android 12, and several on Samsung S21 with Android 11… It happens most often on this call:

String uas = WebSettings.getDefaultUserAgent(context);

I suspect that it happens only if called when no WebView control was created yet, as so far I did not find crashes from similar calls later in the app, when the control was created in it.怀疑只有在尚未创建 WebView 控件时调用它才会发生,因为到目前为止,当在其中创建控件时,我没有在应用程序中发现类似调用的崩溃。 Surrounding this line with try - catch does not help, as the crash seems to happen in another thread.用 try - catch 围绕这条线没有帮助,因为崩溃似乎发生在另一个线程中。

Greg格雷格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM