theanilpaudel
theanilpaudel

Reputation: 3478

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

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

// 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

Upvotes: 3

Views: 2894

Answers (2)

gregko
gregko

Reputation: 5822

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

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:

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. Surrounding this line with try - catch does not help, as the crash seems to happen in another thread.

Greg

Upvotes: 1

Thành Lê
Thành Lê

Reputation: 11

I have the same issue, due I move MobileAds.initialize from the Application class to another class. You can try to init MobileAds.initialize at Application class

Upvotes: 1

Related Questions