'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated
Asked Answered
K

2

20

After upgrading Firebase libraries to

implementation "com.google.firebase:firebase-messaging:18.0.0"
implementation 'com.google.firebase:firebase-config:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'

and syncing Gradle, I got warning:

'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated. Deprecated in Java
'setDeveloperModeEnabled(Boolean): FirebaseRemoteConfigSettings.Builder!' is deprecated. Deprecated in Java

in these lines:

//Setting Developer Mode enabled to fast retrieve the values
firebaseRemoteConfig.setConfigSettings(
    FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG)
        .build())
Keturahkeung answered 21/5, 2019 at 7:52 Comment(1)
related question: #56019791Farandole
K
28

After reading setConfigSettings and setDeveloperModeEnabled I changed the code to:

firebaseRemoteConfig.setConfigSettingsAsync(
    FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(3600L)
        .build())

After upgrading to com.google.firebase:firebase-config:19.0.0 the method setDefaults was also deprecated. Replace it with setDefaultsAsync.

On first run of an application firebaseRemoteConfig won't fetch data and will return default values. To get actual values and cache them see Android Firebase Remote Config initial fetch does not return value.

Instead of 3600L you can use time like TimeUnit.HOURS.toSeconds(12) (as proposed by @ConcernedHobbit).

Keturahkeung answered 21/5, 2019 at 7:53 Comment(13)
I had to add "new": firebaseRemoteConfig.setConfigSettingsAsync(new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(3600L).build());Sartorial
@Michalsx, yes, for Java. Thanks!Keturahkeung
@Keturahkeung how did you end up with "3600L" i was trying to find out what the right interval should be/ was before with developer mode set to enabled. All i could find inside the firebase code led me to believe it should be "0L" for dev mode but maybe i am missing something here ? github.com/firebase/firebase-android-sdk/blob/…Farandole
@MartinJäkel, you know, I didn't experiment with that version of the library, but tried before (in 2018 year). Because setConfigSettingsAsync doesn't depend on dev/release mode, we can use one constant for both (but can use different). As I learnt before, 0L is not a good value, as it led to bugs. I don't remember them, but probably it synchronized too frequently and eventually did't sync at all or gave failure instead of success in callback.Keturahkeung
@MartinJäkel, see also github.com/udacity/and-nd-firebase/issues/….Keturahkeung
How is setDeveloperModeEnabled related to setMinimumFetchIntervalInSeconds exactly? What does it do? And what is the default value for setMinimumFetchIntervalInSeconds ?Sparteine
@androiddeveloper, thanks for the question. DEFAULT_MINIMUM_FETCH_INTERVAL_IN_SECONDS = HOURS.toSeconds(12);. As I understood, during enabled DeveloperMode you can read values from FRC without any delay (get instant values), so it looks like fetch interval = 0 sec. But there is some difference, because setting the interval to 0 will lead to not synchronizing in the future. That was a possibility to test an application without waiting for fetching new values.Keturahkeung
@Keturahkeung I see. I think that by naming it "interval", it's between fetches. Not the first one.Sparteine
@androiddeveloper, agree with you. I think, on the first run we will receive default values. Maybe on the second run we will get right ones. And after passing fetch interval we will again get new values (if they have changed).Keturahkeung
@Keturahkeung So what do you use it for debug vs non-debug?Sparteine
@androiddeveloper, currently I use this code for both cases, because we seldom change anything in FRC. If you want to check faster in debug build, you can use the solution of ConcernedHobbit.Keturahkeung
@Keturahkeung But if you set it to the default, why bother setting it at all? We have to use setConfigSettingsAsync , even if we don't change anything?Sparteine
Let us continue this discussion in chat.Keturahkeung
C
7

To supplement CoolMind's answer, I found you have (at least) two options when it comes to setting the minimum fetch interval (setMinimumFetchIntervalInSeconds). You can either do as CoolMind said when you build your remoteConfig object (in Kotlin):

firebaseRemoteConfig.setConfigSettingsAsync(
    FirebaseRemoteConfigSettings.Builder()
        .setMinimumFetchIntervalInSeconds(TimeUnit.HOURS.toSeconds(12))
        .build())

or you can set the value within your fetch command as a supplied parameter. This example is also in Kotlin, and I've expanded my code to try and make it very clear what's going on:

remoteConfig.setConfigSettingsAsync(FirebaseRemoteConfigSettings.Builder().build())

// Fetch the remote config values from the server at a certain rate. If we are in debug
// mode, fetch every time we create the app. Otherwise, fetch a new value ever X hours.
var minimumFetchInvervalInSeconds = 0
if (BuildConfig.DEBUG) { 
    minimumFetchInvervalInSeconds = 0 
} else { 
    minimumFetchIntervalInSeconds = TimeUnit.HOURS.toSeconds(12) 
}

val fetch: Task<Void> = remoteConfig.fetch()

fetch.addOnSuccessListener {
    remoteConfig.activate()
    // Update parameter method(s) would be here
}
Chumash answered 5/3, 2020 at 0:9 Comment(2)
Thanks! I agree with you, in build configuration we can change interval to zero.Keturahkeung
Agree with you, looking at androidwave.com/firebase-remote-config and blog.mindorks.com/…, I found that they also had set 0 seconds in debug build.Keturahkeung

© 2022 - 2024 — McMap. All rights reserved.