2
votes

If I add the firebase_core to my flutter project, it doesn't run on Android. In iOS it's ok.

I have this gradle error.

    Launching lib/main.dart on Android SDK built for x86 in debug mode...
    Initializing gradle...
    Resolving dependencies...
    Running Gradle task 'assembleDebug'...
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

    FAILURE: Build failed with an exception.

    * What went wrong:

        Could not determine the dependencies of task ':firebase_core:compileDebugAidl'.
        > Could not resolve all task dependencies for configuration ':firebase_core:debugCompileClasspath'.
           > Could not find com.google.firebase:firebase-core:.
             Required by:
                 project :firebase_core

  • pubspec:

    dependencies:
      date_format: ^1.0.6
      flutter:
        sdk: flutter

      url_launcher: ^5.0.2
      webview_flutter: ^0.3.5+3
        #path: ./../webview_flutter
      shared_preferences: ^0.5.1+2
      local_auth: ^0.4.0+1
      http: ^0.12.0+1
      xml: ^3.3.1
      #flutter_auth_buttons: ^0.3.1
      flutter_masked_text: ^0.8.0
      path_provider: ^0.5.0+1
      base32: ^1.0.1
      #json_serializable: ^2.0.3
      get_it: ^1.0.3
      rxdart: ^0.21.0
      flutter_html: ^0.9.6
      sqflite: ^1.1.3
      archive: ^2.0.8
      percent_indicator: ^1.0.14
      flutter_statusbarcolor: ^0.2.0
      flutter_inappbrowser: ^1.1.1
      scoped_model: ^1.0.1

      #Firebase
      firebase_core: ^0.3.1+1
      firebase_analytics: ^2.1.1

  • build.gradle

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

        dependencies {

            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

            classpath 'com.google.gms:google-services:3.2.1'

            classpath 'com.android.tools.build:gradle:3.2.1'
        }
    }

    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
    }

    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'androidx.fragment' &&
                        !details.requested.name.contains('androidx')) {
                    details.useVersion "1.0.0"
                }
            }
        }
    }

  • app/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 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 "xxx"
>         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 {
>     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 'com.google.firebase:firebase-core:16.0.8' }
> 
> apply plugin: 'com.google.gms.google-services'

So what can I do to solve this? As I said it works on iOS and I can see the Analytics Dashboard ok in the Firebase console.

More info... If I open the Android module in Android Studio, it returns this gradle error:

gradleerror

3

3 Answers

2
votes

I solved the problem. I did something crazy but my project is running.

I have other project that was working well with Firebase, so I started to compare the versions of everything... After some hours I find out that the problem was the "firebase-bom" from firebase-core 0.3.2 dependency.

So, thats is the resume of what I did to solve the problem:

1) The project that was working uses: firebase_core: 0.3.1 and mine was using firebase_core: 0.3.2. 2) I tried to use this version 0.3.1, but I don't know why, inside Android Studio I can see that the build.gradle from 0.3.2 was cached.

I realised that, because after open the android folder on Android Studio, it's possible to see all the dependencies like in this picture. The contents of this file was different from my other project that worked well.

enter image description here

So I right-click on this build.gradle file and opened in finder:

And for my surprise it opens in the 0.3.2 location of the firebase-core plugin, but I was using the 0.3.1 version.

/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.3.2/android/build.gradle

So I did something crazy.

I replaced all the contents off this file:

/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.3.2/android/build.gradle

And I copied everything from here:

/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.3.1+1/android/build.gradle

The difference is this line:

implementation 'com.google.firebase:firebase-bom:17.0.0'

It seems that with this "firebase-bom" dependency breaks my project.

After this my project executed well on android and Firebase works... I did some tests with Firebase Remote Config and everything is ok.

I really appreciate if somebody can explain me why this happen and a better way to solve this.

0
votes

change your repositories section with

repositories {
            jcenter()
            maven { url 'https://maven.google.com' }
        }

as the repository google() is just a shorthand to maven { url 'https://maven.google.com' } available in Gradle 4+ as explained in this answer .

0
votes

Make a small change in pubspec.yaml. Change firebase_core: ^0.3.1+1 version with firebase_core: 0.3.1+1 . Just remove ^ . New update of firestore creating this issue.