Flutterfire: [firebase_database] Unable to resolve dependency for

Created on 14 Nov 2019  Â·  17Comments  Â·  Source: FirebaseExtended/flutterfire

I am new to flutter development. I want to use the firebase database. I was able to connect to firebase using the firebase analytics plugin but I was not successful in using the firebase database.

I tried to add the plugins one at a time to know where did the issue come from and now I am sure it is the firebase_database plugin.

I have successfully added the following package:

firebase_core: ^0.4.0+9
firebase_analytics: ^5.0.2
firebase_auth: ^0.14.0+5

but when I add

firebase_database: ^3.1.0

I get the below error
Finished with error: Gradle task assembleDebug failed with exit code 1

This error appears when I run the default flutter application (The counter app) on my Android mobile.
So I open the Android module in Android Studio to get more details about the error.
I got the following error

ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:1.1.1.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:common:1.1.1.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:common:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database


ERROR: Failed to resolve: com.google.firebase:firebase-common:16.0.6
Show in Project Structure dialog
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.core:common:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.core:common:1.1.1.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:1.0.0.
Show Details
Affected Modules: firebase_database

This is my pubspec.yaml file

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  firebase_core: ^0.4.0+9
  firebase_analytics: ^5.0.2
  firebase_auth: ^0.14.0+5
  firebase_database: ^3.1.0


dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

Also, below is my project level my build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

Below is my app level build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.labstabs.riskometer"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    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'

customer-response bug

Most helpful comment

Finally I have solved my issue by having this in Project build.gradle.

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.3.3'
    }

Important: Don't update to latest gradle version. Just keep it to 3.2.1

And by adding these in App level build.grade

dependencies {
    implementation "android.arch.lifecycle:extensions:1.1.1"
    testImplementation "android.arch.core:core-testing:1.1.1"
}

All 17 comments

Hi @suha-glal
could you please provide your updated flutter doctor -v ?
Thank you

@iapicca Commenting here because this issue is very close to the one I mentioned in this Flutter issue.

Hi @iapicca ,

I have replyed without tagging you, sorry.

Here is my flutter doctor -v

[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.14.4 18E226, locale en-AE)
    • Flutter version 1.9.1+hotfix.6 at /Users/soha/Documents/flutter
    • Framework revision 68587a0916 (9 weeks ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0


Hi @suha-glal
thank you for providing your flutter doctor

Hi @iapicca ,

I tested the app yesterday and it still didnot work.
So I started fresh today and created a new flutter app with the same configurations.
This time I got the following error in Flutter console

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':firebase_database:debugCompileClasspath'.
> Could not find com.google.firebase:firebase-common:16.0.6.
  Searched in the following locations:
    - file:/Users/soha/Library/Android/sdk/extras/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - file:/Users/soha/Library/Android/sdk/extras/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - file:/Users/soha/Library/Android/sdk/extras/google/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - file:/Users/soha/Library/Android/sdk/extras/google/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - file:/Users/soha/Library/Android/sdk/extras/android/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - file:/Users/soha/Library/Android/sdk/extras/android/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
  Required by:
      project :firebase_database
> Could not find com.google.firebase:firebase-common:16.0.6.
  Searched in the following locations:
    - file:/Users/soha/Library/Android/sdk/extras/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - file:/Users/soha/Library/Android/sdk/extras/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - file:/Users/soha/Library/Android/sdk/extras/google/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - file:/Users/soha/Library/Android/sdk/extras/google/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - file:/Users/soha/Library/Android/sdk/extras/android/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - file:/Users/soha/Library/Android/sdk/extras/android/m2repository/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.pom
    - https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.6/firebase-common-16.0.6.jar
  Required by:
      project :firebase_database > com.google.firebase:firebase-database:16.0.6

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 38s
Finished with error: Gradle task assembleDebug failed with exit code 1

My Flutter doctor

[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.14.4 18E226, locale en-AE)
    • Flutter version 1.9.1+hotfix.6 at /Users/soha/Documents/flutter
    • Framework revision 68587a0916 (10 weeks ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/soha/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.2.1, Build version 11B500
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 41.1.2
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (2 available)
    • SM G950F          • ce10171a5253542c05                   • android-arm64 • Android 9 (API 28)
    • iPhone 11 Pro Max • 117210A5-B40B-4346-A6C1-D5A01EDD2107 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-2
      (simulator)

• No issues found!

@iapicca Thank you for your help.

Should I just add the below line to android app level gradle file

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

Hi @iapicca ,

So I have added the below line to android module app level build.gradle file

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

I got the following error as a result:

FAILURE: Build failed with an exception.

* What went wrong:
Failed to capture fingerprint of input files for task ':app:checkDebugClasspath' property 'compileClasspath' during up-to-date check.
> In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[16.0.
  5]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

  Dependency failing: com.google.firebase:firebase-measurement-connector-impl:17.0.4 -> com.google.android.gms:play-servic
  es-measurement-base@[16.0.5], but play-services-measurement-base version was 16.5.0.

  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 on project 'firebase_analytics' which depends onto com.google.firebase:[email protected].
  0
  -- Project 'app' depends onto com.google.firebase:[email protected]

  For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
  endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
  github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b
  uild.gradle file.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Finished with error: Gradle task assembleDebug failed with exit code 1

@iapicca I am also facing same issue.

Hi @shah-xad,
You should mention @iapicca

@suha-glal do you have any alternative for now?? As lower versions are also not working..

Hi @iapicca ,
Hello @shah-xad I did not find alternative solution....I have the same issue lower version donot work ....I had to implement part of the application I am working on using Java (Android) to speed up the data collection process. Once this bug is fixed I can implement the same part using Flutter.

Finally I have solved my issue by having this in Project build.gradle.

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.3.3'
    }

Important: Don't update to latest gradle version. Just keep it to 3.2.1

And by adding these in App level build.grade

dependencies {
    implementation "android.arch.lifecycle:extensions:1.1.1"
    testImplementation "android.arch.core:core-testing:1.1.1"
}

Hi @shah-xad ,

Can you please share with me your

  1. app-level build.gradle
  2. project-level build.gradle
  3. pubspec.yaml

I added the dependencies you mentioned but the problem is still persistent for me.

Hi @suha-glal it's working perfect here. If doesn't work, please try to create a new project and then try it.

pubspecs.yaml

name: myapp
description: MyApp

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  provider: ^3.1.0+1
  firebase_core: ^0.4.2
  firebase_storage: ^3.0.8
  firebase_database: ^3.1.0


  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

  uses-material-design: true


project leve build.gradle

buildscript {
    ext.kotlin_version = '1.3.60'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'  // Google Services plugin

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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


app level build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.shahxad.myapp"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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'
    implementation "android.arch.lifecycle:extensions:1.1.1"
    testImplementation "android.arch.core:core-testing:1.1.1"

}

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


Hi @suha-glal
are you still experiencing the issue with the latest stable version of flutter
and the latest version of firebase_database?
thank you

Hi @suha-glal
are you still experiencing the issue with the latest stable version of flutter
and the latest version of firebase_database?
thank you

No it's fine now.

Hi @suha-glal
thank you for telling me know

Was this page helpful?
0 / 5 - 0 ratings