20

I followed the steps in registering my mobile application in firestore but when I try running the code I get the following error. I have downloaded the google services.json from firestore while registering my app and added it to android/app level of my project. Also I have added 'com.google.firebase:firebase-analytics-ktx' in my android/app/build gradle file

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find com.google.firebase:firebase-analytics-ktx:.
     Required by:
         project :app

* 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
Exception: Gradle task assembleDebug failed with exit code 1

My project level build gradle is as below

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

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.4'
    }
}

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
}
 

My app level build gradle is as below

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 28

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

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.ashniz.firestore_time_compare"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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 {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics-ktx'
}

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

Does anyone know how to fix this issue? Thank you

1
  • 1
    If you want to add Firebase analytics to your Flutter app, you should follow the instructions in the documentation. This does not involve changing build.gradle - there are flutter plugins for this. firebase.google.com/docs/flutter/setup Commented Nov 13, 2020 at 16:25

7 Answers 7

24

try to replace this dep

implementation 'com.google.firebase:firebase-analytics-ktx'

with

implementation 'com.google.firebase:firebase-analytics:17.5.0'
21

I could only get the firebase BoM working with build.gradle.kts like this:

implementation(platform("com.google.firebase:firebase-bom:28.4.1"))
implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ktx")
4
  • 2
    Thank you, putting platform inside the parens was the missing piece. Commented Aug 25, 2021 at 20:16
  • It saved me — implementation platform("com.google.firebase:firebase-bom:28.4.1") Commented Sep 24, 2021 at 17:24
  • 1
    BOOM! This worked for me. Thanks!
    – langsmith
    Commented Nov 11, 2021 at 3:12
  • Thanks, adding platform for Firebase BoM is the key
    – prashant
    Commented Feb 7 at 12:50
16

I had a similar issue, in my case I was using BoM, but I have declared the BoM dependency like

implementation 'com.google.firebase:firebase-bom:28.0.1'  // without platform

instead of

implementation platform('com.google.firebase:firebase-bom:28.0.1')
1
  • yes it worked this way!
    – oyeraghib
    Commented Nov 4, 2021 at 13:51
12

Instead of depending on specific versions of different Firebase libraries that might be incompatible, you might want to start using Bill of Materials, such as:

dependencies {
  // Import the BoM for the Firebase platform
  implementation platform('com.google.firebase:firebase-bom:26.5.0')

  // Declare the dependencies for the desired Firebase products without specifying versions
  implementation 'com.google.firebase:firebase-analytics-ktx'
  implementation 'com.google.firebase:firebase-firestore-ktx'
}

The Firebase Android BoM (Bill of Materials) enables you to manage all your Firebase library versions by specifying only one version — the BoM's version.

When you use the Firebase BoM in your app, the BoM automatically pulls in the individual library versions mapped to BoM's version. All the individual library versions will be compatible. When you update the BoM's version in your app, all the Firebase libraries that you use in your app will update to the versions mapped to that BoM version.

Learn more at https://firebase.google.com/docs/android/learn-more#bom

1

I had the same issue, the Bom implementation that worked for me was this -

implementation platform('com.google.firebase:firebase-bom:29.2.1')

and as mentioned in docs when using Bom implementation we don't require to specify the version of analytics

The following should be used with java -

implementation 'com.google.firebase:firebase-analytics'

With java

and with kotlin-

implementation 'com.google.firebase:firebase-analytics-ktx'

with kotlin

The following not be used in conjunction with Bom

implementation 'com.google.firebase:firebase-analytics:17.5.0'

bom take cares of version

You can visit - https://firebase.google.com/docs/android/learn-more?authuser=0&hl=en#bom for more on the Bill of Materials (BoM)

0

All you need that update flutter sdk by running that command in terminal:

flutter upgrade

After completing the update, build your new project and link it to firebase but make sure that in 'PROJECT_PATH/android/app/build.gradle', minSdkVersion is 19 or higher.

applicationId "com.example.flutter_application_1"
    minSdkVersion 19 // here 
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Feb 12, 2022 at 11:37
0

try adding this to your biuld.gradle file:

implementation 'com.google.firebase:firebase-auth-ktx:21.1.0'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.