firebase-kotlin-sdk icon indicating copy to clipboard operation
firebase-kotlin-sdk copied to clipboard

Using remote config with custom Firebase app throws NullPointerException on iOS

Open jimmymorales opened this issue 8 months ago • 1 comments
trafficstars

Running

      val app = Firebase.app("ExampleApp")
      Firebase.remoteConfig(app)

throws:

kotlin.NullPointerException
    at 0   CoraSDK                             0x105c38c2b        kfun:kotlin.Throwable#<init>(){} + 75 
    at 1   CoraSDK                             0x105c32adf        kfun:kotlin.Exception#<init>(){} + 67 
    at 2   CoraSDK                             0x105c32caf        kfun:kotlin.RuntimeException#<init>(){} + 67 
    at 3   CoraSDK                             0x105c32e7f        kfun:kotlin.NullPointerException#<init>(){} + 67 
    at 4   CoraSDK                             0x105c655e7        ThrowNullPointerException + 127 
    at 5   CoraSDK                             0x105eda10b        kfun:dev.gitlive.firebase#<get-app>__at__dev.gitlive.firebase.Firebase(){}dev.gitlive.firebase.FirebaseApp + 355 
    at 6   CoraSDK                             0x105f82e87        kfun:dev.gitlive.firebase.remoteconfig#remoteConfig__at__dev.gitlive.firebase.Firebase(dev.gitlive.firebase.FirebaseApp){}dev.gitlive.firebase.remoteconfig.FirebaseRemoteConfig + 331 
    at 7   CoraSDK                             0x105afe71f  

This is only occurring for the iOS implementation and the reason is that when creating the Remote Config instace the default app is being used instead of the custom one, in the case where the default one doesn't existing it throws.

In FirebaseRemoteConfig.kt line 30, instead of doing this:

public actual fun Firebase.remoteConfig(app: FirebaseApp): FirebaseRemoteConfig = FirebaseRemoteConfig(
    FIRRemoteConfig.remoteConfigWithApp(Firebase.app.ios as objcnames.classes.FIRApp),
)

It should be:

public actual fun Firebase.remoteConfig(app: FirebaseApp): FirebaseRemoteConfig = FirebaseRemoteConfig(
    FIRRemoteConfig.remoteConfigWithApp(app.ios as objcnames.classes.FIRApp),
)

If PRs are welcomed, I'm more than happy to create one for this simple fix.

jimmymorales avatar Feb 24 '25 16:02 jimmymorales