【发布时间】:2019-08-21 07:50:20
【问题描述】:
对于同一问题,这里有很多问题,但没有一个解决根本原因或我所看到的 - 因此建议的答案没有帮助。
我的应用程序构建没有问题,但是,在运行时,我不断收到运行时异常:
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)
我从其他问题中看到,这可能与具有不同版本的依赖项中的支持库有关,因此我通过将以下内容添加到我的 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'
}
}
}
}
但是,这似乎没有什么不同。我在依赖树中看到所有支持版本确实是 28.0.0,如 resoutionStrategy 中指定的那样,所以看起来该部分正在工作。
我的完整 gradle 文件是 here。
我已经发布了我的 gradle 依赖项 (./gradlew app:dependencies) here。
此时,我正在尝试学习如何正确调试它。我完全不知所措。 有人知道如何调试此类错误吗?
当然,我已经多次清理过缓存并使其失效。
更新
我发现问题确实出在 FirebaseApp 的 initializeAllApis 部分。具体线路是:
boolean isDeviceProtectedStorage = ContextCompat.isDeviceProtectedStorage(this.applicationContext);
ContextCompat 表示来自com.android.support:support-compat:28.0.0。
所以这似乎是引用最新的,但是当这行执行时,我得到了上面的堆栈跟踪。因此,虽然我正在缩小范围,但我仍然不确定为什么会抛出此错误或如何修复它。
【问题讨论】:
-
转到构建 -> 分析 APK 并检查
classes116。看看你是否通过那里引用了正确的库。可能是您使用的设备具有 sdk 版本 if23并使用默认支持库。
标签: android firebase gradle android-gradle-plugin firebase-cloud-messaging