I'm facing an issue with Firebase Analytics event logging in my Flutter app. Events are not being logged on Android devices, although they work perfectly on iOS. The following error message appears in adb logcat:
05-27 14:55:08.562 V/FA-SVC ( 6814): Network upload failed. Will retry later. code, error: 0, java.net.ConnectException: Failed to connect to
app-measurement.com/[::]:443: btlq.run(:com.google.android.gms@242013038@24.20.13 (190400-633713831):154)
Troubleshooting:
Verified Firebase Configuration: Double-checked the correct placement of GoogleService-Info.plist (iOS) or google-services.json (Android), project registration in Firebase, and ensured Analytics is enabled.
Network Connectivity: Confirmed a stable internet connection by testing on different networks.
Google Play Services: Verified version compatibility between the app and the device.
Dependency Conflicts: Resolved any conflicts using flutter pub outdated and flutter pub upgrade.
Clean Build: Cleaned and rebuilt the app with flutter clean and flutter build apk.
Firewall/Proxy: Checked for any firewall or proxy restrictions that might be blocking the connection (if applicable).
Isolation Test: Created a new Firebase project and a new Flutter project with only Analytics for testing purposes.
Environment:
Flutter Version: 3.19.6 (3.22.1) (you can mention both versions if using the channel)
Google Play Services: 4.3.15
Dependencies:
firebase_analytics: ^10.10.6
firebase_auth: ^4.19.6
firebase_core: ^2.31.1
Relevant files:
project/build.gradle
buildscript {
ext.kotlin_version = '1.9.22'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
// START: FlutterFire Configuration
classpath 'com.google.gms:google-services:4.4.1'
// END: FlutterFire Configuration
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
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
}
app/build.gradle
plugins {
id "com.android.application"
id("com.google.gms.google-services")
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
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'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "ro.test.test"
compileSdkVersion 34
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 "ro.daredigital.wishmo"
// 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 24
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
// Import the BoM for the Firebase platform
implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
// Add the dependency for the Analytics library
// When using the BoM, you dopn't specify versions in Firebase library dependencies
implementation("com.google.firebase:firebase-analytics")
}