1

When I try to update my targetSdkVersion from 27 to 28, I get the error:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.baus_systems.inventorycount, PID: 2594
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;
    at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source:4)
    at com.google.firebase.FirebaseOptions.fromResource(com.google.firebase:firebase-common@@19.0.0:156)
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@19.0.0:240)
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@19.0.0:51)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1922)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1897)
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@19.0.0:45)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6708)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6255)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6151)
    at android.app.ActivityThread.access$1100(ActivityThread.java:208)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:205)
    at android.app.ActivityThread.main(ActivityThread.java:6991)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.R$string" on path: DexPathList[[zip file "/data/app/com.baus_systems.inventorycount-y-SEoNnBinme-b9ebwn0xg==/base.apk"],nativeLibraryDirectories=[/data/app/com.baus_systems.inventorycount-y-SEoNnBinme-b9ebwn0xg==/lib/arm, /data/app/com.baus_systems.inventorycount-y-SEoNnBinme-b9ebwn0xg==/base.apk!/lib/armeabi-v7a, /system/lib, /product/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source:4) 
    at com.google.firebase.FirebaseOptions.fromResource(com.google.firebase:firebase-common@@19.0.0:156) 
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@19.0.0:240) 
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@19.0.0:51) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1922) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1897) 
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@19.0.0:45) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:6708) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6255) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6151) 
    at android.app.ActivityThread.access$1100(ActivityThread.java:208) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:205) 
    at android.app.ActivityThread.main(ActivityThread.java:6991) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884) 

This is the dependencies section of my build.gradle:

dependencies {
    def lifecycle_version = "1.1.1"
//    def multidex_version = "2.0.1"
//    implementation 'androidx.multidex:multidex:2.0.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.annotation:annotation:1.0.2'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    testImplementation 'junit:junit:4.12'
    implementation('androidx.constraintlayout:constraintlayout:1.1.3')
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
    implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
    implementation 'com.google.firebase:firebase-ml-model-interpreter:16.2.4'
    implementation 'com.drewnoakes:metadata-extractor:2.11.0'
    // AWS Mobile Client
    implementation('com.amazonaws:aws-android-sdk-mobile-client:2.6.+@aar') { transitive = true }
    // AWS Core
    implementation('com.amazonaws:aws-android-sdk-core:2.3.+')
    // AWS S3
    implementation('com.amazonaws:aws-android-sdk-s3:2.3.+')
    // AWS Cognito
    implementation('com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.3.+')
    implementation 'com.amazonaws:aws-android-sdk-cognitoauth:2.4.7@aar'
    //AWS Lambda
    implementation('com.amazonaws:aws-android-sdk-lambda:2.2.+')

    implementation project(':plugin')
}

I have tried updating the firebase dependencies to the latest versions (which required updating the minSdkVersion from 15 to 16), which has no effect (and I'm not sure whether this is a viable option, as I seem to remember my coworker saying something about barcode scanning not being supported if I take these versions too high). Updating all dependencies has the app crash with no error, and I haven't yet figured out which ones are to blame; I decided I would focus on this issue as much as possible instead of inviting more trouble without reason. I've tried enabling multidex a couple different ways, as I saw that suggested somewhere; none of them seem to help. There are a few other things I've tried as well, and have lost the pages for, but nothing I've tried has helped.

Any help in resolving this error would be appreciated, as I cannot update the app in the Play Store until I can upgrade to 28.

Trevortni
  • 688
  • 8
  • 23
  • can i know what stacktrace are you getting when targetSdkVersion =29. – jose praveen Mar 12 '20 at 12:41
  • @JosePraveen, The stack trace looks the same if I raise it to 29, except for a few version numbers here and there that I changed while trying to find a solution. It's way too big to fit into a comment, but I can add it to the original question if you want to confirm that it's identical for yourself. – Trevortni Mar 12 '20 at 17:39
  • i hope you are updating the app in the play store, better try with API level 29 and add stacktrace. read this minimum [targetversion](https://support.google.com/googleplay/android-developer/answer/113469#targetsdk) – jose praveen Mar 12 '20 at 17:43
  • @JosePraveen, That's the problem, I'm not able to update the app in the play store because I cannot update the app to 28. – Trevortni Mar 12 '20 at 18:45
  • 1
    So I decided to roll back to 27 so I could try updating all the dependencies with the targetSdkVersion in a working state, and now I keep getting the same issue in 27. I think I'm just going to try to get it working in 29 from here on out. This is driving me insane. – Trevortni Mar 12 '20 at 19:13
  • For what it's worth, the spot that is breaking appears to be when Firebase is loading options from internal resources, it's trying to load the resource string `com.google.android.gms.common.R.string.common_google_play_services_unknown_issue` as a default error value before trying to load the actual options via "google_app_id", but it can't find R.string in the DexPathList. If it were my code, I could fix the code that is broken, but I can't fix this code because it's in internal code. – Trevortni Mar 12 '20 at 20:25
  • try this workaround to fix this issue asap. https://stackoverflow.com/a/33162131/8035260 – jose praveen Mar 12 '20 at 23:55
  • @JosePraveen, None of the things I've tried with MultiDex over the past week have had any effect on the issue, including subclassing from `MultiDexApplication` and calling `MultiDex.install()` in `attachBaseContext()`. The only thing I can see there that I haven't tried is toggling Instant Run, because it doesn't appear to have a toggle in the settings anymore. – Trevortni Mar 13 '20 at 01:06
  • There is nonthing to do with 27, 28 or 29 SDK. It is totally the gradle and firebase problem. Take a look at this link from Android gradle https://developer.android.com/studio/releases/gradle-plugin#agp-missing-manifest – CodingTT Mar 13 '20 at 01:33
  • @CodingTT, Thank you, backing off on the Gradle version did fix it, and now I can run it on targetSdkVersion 29. I'm not sure if I can make an answer to this question without figuring out exactly what in the Gradle update broke it, but I can at least get my update to our customers and then investigate further. – Trevortni Mar 13 '20 at 18:32

1 Answers1

1

As mentioned in a comment under the question, the issue turned to to be raising Gradle past 3.6.0, not raising targetSdkVersion. But what was the problem with Gradle?

This answer led me to updating my Firebase and ObjectBox versions, which I thought had done before, but apparently not. But this led to an issue Type androidx.appcompat.resources.R$attr is defined multiple times, which resisted Cleans, Rebuilds, and Invalidate Caches. This was finally cleared up by deleting the .gradle folder and Cleaning and Rebuilding.

But there was still one more issue remaining: Invoke-customs are only supported starting with android O. I still have no idea what that means, but setting

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

in my build.gradle, as suggested here, seems to have gotten me past that.

Trevortni
  • 688
  • 8
  • 23