firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 573 forks source link

Remote Config Android, Cached deleted after 2 app restart #4279

Closed pamainville-clgx closed 1 year ago

pamainville-clgx commented 1 year ago

[READ] Step 1: Are you in the right place?

Remote config with KMM, in an actual definition for android. In a other module than the main UI Module. Also using firebase performance that use Remote config

After 2 app restart, the activated cached seem to be deleted and just returning default value

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Remote config return default value after 2 app restart

Steps to reproduce:

uninstall the app. start the app 2 time 3rd time the remote config return default values from xml

Relevant Code:

This is the actual implementation of our Firebase remote config, in the KMM libraries we build. No "Firebase.remoteConfig" elsewhere in the code... but still, after a lot of trouble shooting and understanding a bit the code, I see the get on the active config return null all the time after 2 restart, was not able to see the delete file for the active config file saved!

actual open class RemoteConfigDataSourceImpl : RemoteConfigDataSource {

    override fun getBoolean(key: RemoteConfigKey) =
        Firebase.remoteConfig.getBoolean(key.key)

    override fun getString(key: RemoteConfigKey) =
        Firebase.remoteConfig.getString(key.key)

    override suspend fun initialize(): Boolean =
        suspendCoroutine { continuation ->

             val configSettings = remoteConfigSettings {
                minimumFetchIntervalInSeconds = 3600
            }
            Firebase.remoteConfig.setConfigSettingsAsync(configSettings)
            Firebase.remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)

            Firebase.remoteConfig
                .fetchAndActivate()
                .addOnFailureListener {
                    continuation.resume(false)
                }
                .addOnCompleteListener {
                    continuation.resume(true)
                }
        }
}
google-oss-bot commented 1 year ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

argzdev commented 1 year ago

Thanks for reporting, @pmainville-clgx. Amazing work on using Firebase in KMM, this is quite an interesting use case. That said, I wonder why remote config would fail on the 3rd time. Could you answer a few questions below:

  1. Is this a consistent issue that always happens only during the 3rd time and not in other iterations?
  2. Is this behavior reproducible on any devices/emulator? Or is it only on a specific device model?
  3. Any particular Android version or is it reproducible on all versions?

Also if there's any chance you could provide a minimal repro of this issue, that'll greatly help us a lot investigating your issue.

pamainville-clgx commented 1 year ago

Hello, Sorry for the delay.

  1. Yes, really consistent issue, I've also noted that in logcat, Firebase performance is not able to fetch it's data on the 3rd time the app start

  2. On any emulator i've tried, even my Pixel XL have the behaviour

  3. for now, I've tried on Pie and Tiramisue.

Hmm, repros is simple from my point of view, delete the app from the device, start it 3 time. Other than that, I'll have to provide our source code!

I've found a workaround, for now, but this sill be problematic in a near future if we release the app like this with the number of users we have, I've call

Firebase.remoteconfig.reset()

I've also tried to find when the activated cash get cleared, but was not able to find it. but, in our case, the 3rd time the app start, the activated cached file is no on the disk anymore from what I've understand.

Also, in our case, in the KMM lib, we can't import or yet find the way to import the BOM of firebase cause platform is not know in the androidCommon. so, we import all latest and greatest version of what is used, that is

val androidMain by getting { dependencies { implementation("io.ktor:ktor-client-okhttp:${Versions.ktor}") implementation("com.squareup.okhttp3:logging-interceptor:4.9.1") implementation("com.google.firebase:firebase-core:${Versions.firebase_core}") implementation("com.google.firebase:firebase-crashlytics:${Versions.firebase_crashlytics}") implementation("com.google.firebase:firebase-crashlytics-ktx:${Versions.firebase_crashlytics}") implementation("com.google.firebase:firebase-analytics:${Versions.firebase_analytics}") implementation("com.google.firebase:firebase-messaging:${Versions.firebase_messaging}") implementation("com.google.firebase:firebase-config-ktx:${Versions.firebase_remote_config}") } }

const val firebase_core = "21.1.1" const val firebase_crashlytics_gradle_plugin = "2.9.2" const val firebase_crashlytics = "18.3.0" const val firebase_analytics = "21.2.0" const val firebase_messaging = "23.1.0" const val firebase_remote_config = "21.2.0"

hope this can help

argzdev commented 1 year ago

Hi @pmainville-clgx, thanks for the details. Those are some interesting findings. Regarding the repro, it's a bit difficult for us to determine what/where the issue might be without being able to test the issue myself, especially since KKM is still in beta and is not officially supported in Firebase.

That said, if you could provide a minimal code repro of the issue (KMM + remote config, no need to provide the entire source code) that will definitely help us test this locally on our side and see the error ourselves. However, if you feel uncomfortable sharing your code, could you kindly guide me into how you ported remote config in a KMM project? Is it just creating a KMM project then adding Firebase Remote Config in androidMain? If so, would this only be available in android? I know this is a lot of work on your side, but I think this is the only way we can move this forward, and I can probably justify an engineer’s time to dig into it with this much evidence.

google-oss-bot commented 1 year ago

Hey @pmainville-clgx. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

svyatoslavpavlov commented 1 year ago

Same problem As i see, json files from /files repo of app are deleting after second start

pamainville-clgx commented 1 year ago

Workin on it today, i'll try to do a sample app that reproduce the bug!

That said, not sure I will find something, pretty sure there is something on our side, but our app is so big that for now, impossible to find out what! Anyway, i'll try!

svyatoslavpavlov commented 1 year ago

I've found out. Bug from my side, another library clears "files" dir on each start.

pamainville-clgx commented 1 year ago

Ok, so, we can close it here, I finally find out too

Like @svyatoslavpavlov find out, we also have a lib that clear the disk.

I was trying to do another sample app to push here, but eventually, was not able to reproduce the bug just with config!

Then, started to wonder about disk access, and we have a few, one for some sort of share pref and one to store some files, the one to store some files, after a fresh install, first, we loged in, at the seccond restart, depending on the login, we fetch a splash screen that we store on local disk, but a function called before to store the disk clean the disk, erasing the cached files from the remote config, and then, 3rd time, it return de default, since he just have fetched...

So, bad use of the file lib.

You can close this issue!

Thad said, thanks for your help! Much appreciated!

argzdev commented 1 year ago

I'm glad you're able to resolve your issue, @pmainville-clgx. Thanks for sharing your investigations as well, @pmainville-clgx and @svyatoslavpavlov. I'm sure this'll help a lot of our fellow developers in the future. That said, I'll close this issue now.