Dansk
Dansk

Reputation: 41

Connecting Firebase to Flutter in Android Studio

Im trying to connect my flutter project in firebase but I keep getting this error

Launching lib\main.dart on sdk gphone x86 in debug mode...

Running Gradle task 'assembleDebug'...

√ Built build\app\outputs\flutter-apk\app-debug.apk.

Installing build\app\outputs\flutter-apk\app-debug.apk...

Debug service listening on ws://127.0.0.1:54542/CBgATS3doF8=/ws

Syncing files to device sdk gphone x86...

E/flutter (15791): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)

E/flutter (15791): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)

E/flutter (15791): <asynchronous suspension>

E/flutter (15791): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)

E/flutter (15791): <asynchronous suspension>

E/flutter (15791): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)

E/flutter (15791): <asynchronous suspension>

E/flutter (15791): #3 main (package:database/main.dart:5:3)

E/flutter (15791): <asynchronous suspension>

E/flutter (15791):

I did many tutorials in youtube but most of them are outdated most of the syntax change but even i find an updated tutorial this is always the case. I follow the steps in adding android in the firebase website

this is my android\build.gradle

buildscript {
    ext.kotlin_version = '1.9.10'
    repositories {
        google()
        mavenCentral()
    }

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

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

this is my app\build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id 'com.google.gms.google-services'
}

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

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

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

android {
    namespace "com.example.database"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.database"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 19
        targetSdkVersion flutter.targetSdkVersion
        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 platform('com.google.firebase:firebase-bom:32.4.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.android.support:multidex:1.0.3'

}

Upvotes: 0

Views: 414

Answers (1)

Dansk
Dansk

Reputation: 41

I changed the version of the classpath 'com.google.gms:google-services:4.4.0' to classpath 'com.google.gms:google-services:4.3.15'. It works I don't know why but I don't get the errors

Upvotes: 3

Related Questions