所有Firebase依赖项的版本都相同,启动后应用仍然崩溃

时间:2019-04-05 12:23:09

标签: android firebase firebase-realtime-database firebase-authentication

我注意到这是一个很常见的问题,因此我做了一些研究,并试图自己解决这个问题,但没有任何积极的结果。因此,如果有人对解决这个问题有任何想法,我将非常感激。我已经坚持了几个小时。

我查看了以下线程:

  1. Firebase database dependecny crashes app-我发现我的所有依赖项版本都应该相同。
  2. Android app crashes-在此线程中,他们建议我应根据google official website使用最新版本。
  3. 还有here我发现了相同的建议-版本应该相同,清理并重建项目等。

我了解的是问题所在: 依赖项不兼容。

注意:我的应用仅在firebase-realtime数据库上运行良好。添加firebase-auth后,它立即崩溃(在Huawei P9 lite上未在仿真器上测试)。

我尝试过的事情:

1)使所有依赖项为最新版本。它无法正常工作-启动后应用仍然崩溃。

implementation 'com.google.firebase:firebase-core:16.0.8'

implementation 'com.google.firebase:firebase-database:16.1.0'

implementation 'com.google.firebase:firebase-auth:16.2.0'

2)基于此link(即16.0.5)将依赖项降级为它们共有的最接近版本。

implementation 'com.google.firebase:firebase-core:16.0.5'

implementation 'com.google.firebase:firebase-database:16.0.5'

implementation 'com.google.firebase:firebase-auth:16.0.5'

3)当我尝试通过工具管理器添加firebase-auth时,     插入了'com.google.firebase:firebase-auth:16.0.3'导致此错误:

ERROR: In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[15.0. 1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.android.gms:play-services-flags:15.0.1 -> com.google.android.gms:play-services-basement@[
15.0.1], but play-services-basement version was 16.0.1.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art ifact with the issue.
-- Project 'app' depends onto com.google.firebase:firebase-core@16.0.5
-- Project 'app' depends onto com.google.firebase:firebase-iid@17.0.3
-- Project 'app' depends onto com.google.firebase:firebase-analytics@16.0.5
-- Project 'app' depends onto com.google.firebase:firebase-common@16.0.4
-- Project 'app' depends onto com.google.android.gms:play-services-stats@16.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-basement@16.0.1
-- Project 'app' depends onto com.google.firebase:firebase-auth-interop@16.0.0
-- Project 'app' depends onto com.google.android.gms:play-services-flags@15.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-tasks@16.0.1
-- Project 'app' depends onto com.google.firebase:firebase-measurement-connector-impl@17.0.3
-- Project 'app' depends onto com.google.android.gms:play-services-base@16.0.1
-- Project 'app' depends onto com.google.firebase:firebase-analytics-impl@16.2.3
-- Project 'app' depends onto com.google.firebase:firebase-database@16.0.5
-- Project 'app' depends onto com.google.firebase:firebase-iid-interop@16.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-base@16.0.4
-- Project 'app' depends onto com.google.android.gms:play-services-ads-identifier@16.0.0
-- Project 'app' depends onto com.google.firebase:firebase-measurement-connector@17.0.1
-- Project 'app' depends onto com.google.firebase:firebase-auth@16.0.3
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-api@16.0.3

这是我的应用程序级别gradle文件的样子:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.test123"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    implementation 'com.google.firebase:firebase-core:16.0.5'

    implementation 'com.google.firebase:firebase-database:16.0.5'

    implementation 'com.google.firebase:firebase-auth:16.0.5'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

这是我的gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {

        // Android Gradle Plugin
        classpath 'com.android.tools.build:gradle:3.3.2'

        // Google Services Plugin
        classpath "com.google.gms:google-services:4.2.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最后是我的日志猫:

04-05 14:04:36.000 906-906/? I/art: Late-enabling -Xcheck:jni
04-05 14:04:36.192 906-906/com.example.test123 W/System: ClassLoader referenced unknown path: /data/app/com.example.test123-1/lib/arm64
04-05 14:04:36.439 906-922/com.example.test123 I/art: Background partial concurrent mark sweep GC freed 11193(638KB) AllocSpace objects, 4(80KB) LOS objects, 21% free, 15MB/19MB, paused 343us total 105.488ms at HeapTaskDaemon thread CareAboutPauseTimes 1
04-05 14:04:36.658 906-957/com.example.test123 W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
04-05 14:04:36.686 906-956/com.example.test123 I/FA: App measurement is starting up, version: 14700
04-05 14:04:36.686 906-956/com.example.test123 I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
04-05 14:04:36.686 906-956/com.example.test123 I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.example.test123
04-05 14:04:36.717 906-906/com.example.test123 I/FirebaseInitProvider: FirebaseApp initialization successful
04-05 14:04:36.723 906-961/com.example.test123 W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
04-05 14:04:36.733 906-961/com.example.test123 I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
04-05 14:04:36.733 906-961/com.example.test123 I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
04-05 14:04:37.017 906-976/com.example.test123 I/System: core_booster, getBoosterConfig = false
04-05 14:04:37.048 906-906/com.example.test123 I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
04-05 14:04:37.254 906-906/com.example.test123 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-05 14:04:37.673 906-906/com.example.test123 I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
04-05 14:04:37.674 906-906/com.example.test123 I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
04-05 14:04:38.485 906-906/com.example.test123 I/Process: Sending signal. PID: 906 SIG: 9

4 个答案:

答案 0 :(得分:1)

问题可能出在您的设备上,它可能没有最新的Google Play服务来支持您的应用所请求的版本。

尝试在您的设备中更新您的Google Play服务,或更改为其他设备并在其中进行测试。

答案 1 :(得分:0)

尝试一下,它可能会起作用。

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'

答案 2 :(得分:0)

当我们使用多个库,其中某些库已经包含在某些库中,但版本不同时,我们遇到了这类问题。为此,您可以强制gradle在任何地方使用该库的单个版本

configurations.all {
 resolutionStrategy {
   force "com.google.firebase:firebase-core:${VERSION_XYZ}”
   force "com.google.firebase:firebase-database:${VERSION_ABC}”
 }}
 dependencies {
   // ... all dependencies here...
 }

就像这样,对每个库都执行此操作,然后在gradle文件中定义它,这可能会对您有所帮助。

答案 3 :(得分:0)

尝试一下,它将对您有用。编码愉快:)

onLocationFetched()