Reputation: 317
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:
GoogleService-Info.plist
(iOS) or google-services.json
(Android), project registration in Firebase, and ensured Analytics is enabled.flutter pub outdated
and flutter pub upgrade
.flutter clean
and flutter build apk
.Environment:
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")
}
Upvotes: 1
Views: 203
Reputation: 394
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:
Ensure that your AndroidManifest.xml file includes the necessary internet permission.
<uses-permission android:name="android.permission.INTERNET"/>
Make sure your Firebase configuration is correctly set up in your Android project.
google-services.json
file is correctly placed in the app
directory.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
}
Ensure there are no network restrictions or firewall settings that might be blocking access to app-measurement.com
.
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.
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.
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.
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
.
adb logcat -s FA FA-SVC Firebase
Ensure Google Play Services are available and up to date on the device.
If you are using a firewall or VPN, try disabling it temporarily to see if it resolves the issue.
Upvotes: 0