Skip to content

Network operation is being attempted on the main thread of app within the Firebase Remote Config library, specifically related to its real-time features #6935

@ohran9

Description

@ohran9

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Android Studio Meerkat | 2024.3.1 Patch 2
  • Firebase Component: Remote Config
  • Component version: 22.1.1

[REQUIRED] Step 3: Describe the problem

A Fatal Exception: android.os.NetworkOnMainThreadException occurring at com.google.firebase.remoteconfig.internal.ConfigRealtimeHttpClient.setIsInBackground (ConfigRealtimeHttpClient.java:413) indicating that a network operation is being attempted on the main thread of our Android application within the Firebase Remote Config library, specifically related to its real-time features.

It occurs on a range of devices (Samsung, Lenovo, Oppo...) with varying Android versions (from 5.0 to 10)

Steps to reproduce:

This is the log from Crashlytics

Fatal Exception: android.os.NetworkOnMainThreadException:
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1318)
at com.android.org.conscrypt.Platform.blockGuardOnNetwork(Platform.java:300)
at com.android.org.conscrypt.OpenSSLSocketImpl.shutdownAndFreeSslNative(OpenSSLSocketImpl.java:1209)
at com.android.org.conscrypt.OpenSSLSocketImpl.close(OpenSSLSocketImpl.java:1204)
at com.android.okhttp.Connection.closeIfOwnedBy(Connection.java:173)
at com.android.okhttp.OkHttpClient$1.closeIfOwnedBy(OkHttpClient.java:77)
at com.android.okhttp.internal.http.HttpConnection.closeIfOwnedBy(HttpConnection.java:137)
at com.android.okhttp.internal.http.HttpTransport.disconnect(HttpTransport.java:135)
at com.android.okhttp.internal.http.HttpEngine.disconnect(HttpEngine.java:600)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.disconnect(HttpURLConnectionImpl.java:134)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.disconnect(DelegatingHttpsURLConnection.java:93)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.disconnect(HttpsURLConnectionImpl.java)
at com.google.firebase.remoteconfig.internal.ConfigRealtimeHttpClient.setIsInBackground(ConfigRealtimeHttpClient.java:413)
at com.google.firebase.remoteconfig.internal.ConfigRealtimeHandler.setBackgroundState(ConfigRealtimeHandler.java:94)
at com.google.firebase.remoteconfig.FirebaseRemoteConfig.setConfigUpdateBackgroundState(FirebaseRemoteConfig.java:715)
at com.google.firebase.remoteconfig.RemoteConfigComponent.notifyRCInstances(RemoteConfigComponent.java:367)
at com.google.firebase.remoteconfig.RemoteConfigComponent.access$100(RemoteConfigComponent.java:64)
at com.google.firebase.remoteconfig.RemoteConfigComponent$GlobalBackgroundListener.onBackgroundStateChanged(RemoteConfigComponent.java:405)
at com.google.android.gms.common.api.internal.BackgroundDetector.zza(com.google.android.gms:play-services-basement@@18.5.0:3)
at com.google.android.gms.common.api.internal.BackgroundDetector.onTrimMemory(com.google.android.gms:play-services-basement@@18.5.0:3)
at android.app.Application.onTrimMemory(Application.java:136)
at android.app.ActivityThread.handleTrimMemory(ActivityThread.java:5140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1726)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6289)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

Relevant Code:

*Code is used in the Application class onCreate method!

 CoroutineScope(Dispatchers.IO).launch {
        try {
            val remoteConfigFirebase = Firebase.remoteConfig

            remoteConfigFirebase.apply {
                fetchAndActivate()
                    .addOnCompleteListener { task ->
                        if (task.isSuccessful) {
                                setRemoteValues(true, task, this)
                        } else {
                            AppLogger.d("ConfigFirebase update failed")
                        }
                    }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions