#StackBounty: #android #firebase #gradle #android-gradle #firebase-cloud-messaging No static method isDeviceProtectedStorage runtime er…

Bounty: 250

There are many questions on here for this same issue, but not one addresses the root cause or what I’m seeing – and thus the proposed answers aren’t helpful.

My app builds with no issues, however, on running, I constantly receieve a runtime exception:

java.lang.NoSuchMethodError: No static method isDeviceProtectedStorage(Landroid/content/Context;)Z in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/com.ohmd-1/base.apk:classes116.dex)
                      at com.google.firebase.FirebaseApp.zzc(Unknown Source)
                      at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                      at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                      at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                      at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
                      at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
                      at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
                      at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)

I see from other questions that this might be related to support libraries in dependencies having different versions, so I have enforced the single library version(s) by adding the following to my gradle:

configurations.all {
    resolutionStrategy {
        force 'com.google.firebase:firebase-core:15.0.2'
        force 'com.google.firebase:firebase-messaging:15.0.2'
    }
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group.equals('com.android.support')) {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }
    }
}

However, this doesn’t seem to make a difference. I see in my dependency tree that all the support versions are indeed 28.0.0 as specified in the resoutionStrategy, so it looks like that portion is working.

My full gradle file is here.

I have posted my gradle dependencies (./gradlew app:dependencies) here.

At this point, I’m trying to learn how to properly debug this. I’m at a complete loss. Does anyone have any idea how to debug this type of error?

I have – of course – cleaned and invalidated caches many times.

UPDATE

I have found that the issue is indeed in the initializeAllApis section of FirebaseApp. The specific line is:

boolean isDeviceProtectedStorage = ContextCompat.isDeviceProtectedStorage(this.applicationContext);

ContextCompat says its from com.android.support:support-compat:28.0.0.

So this appears to be referencing the most recent, yet when this line executes, I get the above stacktrace. So while I’m narrowing it down, I still am not sure why this is error is being thrown or how to fix it.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.