1

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@[email protected] (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")
}

1 Answer 1

0

The issue with Firebase Analytics event logging on Android devices, where events fail to upload due to a java.net.ConnectException, suggests a network connectivity problem. This problem could be due to various factors including network configuration, permissions, or Firebase setup. Here are several steps to help troubleshoot and resolve this issue:

1. Check Internet Permission

Ensure that your AndroidManifest.xml file includes the necessary internet permission.

<uses-permission android:name="android.permission.INTERNET"/>

2. Review Firebase Configuration

Make sure your Firebase configuration is correctly set up in your Android project.

  • Verify that the google-services.json file is correctly placed in the app directory.
  • Ensure that you have added the Firebase plugin to your build.gradle files:

Project-level build.gradle:

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.10' // Use the latest version
    }
}

App-level build.gradle:

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

// Add dependencies
dependencies {
    implementation 'com.google.firebase:firebase-analytics:21.1.0' // Use the latest version
}

3. Check Network Configuration

Ensure there are no network restrictions or firewall settings that might be blocking access to app-measurement.com.

  • If you are behind a corporate or school network, try switching to a different network, such as a mobile hotspot.
  • Ensure that the device is not in airplane mode or has limited connectivity.

4. Update Dependencies

Make sure all your dependencies are up to date, especially Google Play services and Firebase libraries. You can update them via your build.gradle files or through the SDK Manager in Android Studio.

5. Verify Device Time Settings

Ensure that the device's date and time are set correctly. Incorrect time settings can lead to SSL/TLS connection issues, which might cause the connection to Firebase servers to fail.

6. Check for Debugging Issues

If you are running your app in debug mode, try running it in release mode to see if the issue persists. Debug builds can sometimes have different behaviour due to additional debugging overhead.

7. Review ADB Logs

Continue to monitor the adb logcat for more detailed error messages that might provide additional clues. Focus on Firebase-related tags such as FA-SVC, FA, and Firebase.

Example Logcat Command

adb logcat -s FA FA-SVC Firebase

8. Google Play Services Availability

Ensure Google Play Services are available and up to date on the device.

9. Firewall and VPN

If you are using a firewall or VPN, try disabling it temporarily to see if it resolves the issue.

1
  • 1
    Did you create this answer with ChatGPT? - Do note: This is a rhetorical comment. Please read the article attached - TLDR: Using ChatGPT to create any content on SO is banned.
    – DarkBee
    Commented May 27 at 9:41

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