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())
CoolMind
  • 26,736
  • 15
  • 188
  • 224

2 Answers2

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).

CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • 1
    I had to add "new": firebaseRemoteConfig.setConfigSettingsAsync(new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(3600L).build()); – Michalsx Aug 14 '19 at 11:59
  • @Michalsx, yes, for Java. Thanks! – CoolMind Aug 14 '19 at 13:51
  • 1
    @CoolMind 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 ? https://github.com/firebase/firebase-android-sdk/blob/5301121df4727b357293b3b7de00555362f90170/firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigFetchHandler.java#L153 – Martin Jäkel Sep 13 '19 at 07:37
  • 2
    @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. – CoolMind Sep 13 '19 at 14:21
  • 1
    @MartinJäkel, see also https://github.com/udacity/and-nd-firebase/issues/61#issuecomment-531669186. – CoolMind Sep 20 '19 at 14:20
  • 2
    How is `setDeveloperModeEnabled` related to `setMinimumFetchIntervalInSeconds `exactly? What does it do? And what is the default value for `setMinimumFetchIntervalInSeconds ` ? – android developer Sep 01 '20 at 08:15
  • 1
    @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. – CoolMind Sep 01 '20 at 08:26
  • 1
    @CoolMind I see. I think that by naming it "interval", it's between fetches. Not the first one. – android developer Sep 01 '20 at 11:22
  • 1
    @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). – CoolMind Sep 01 '20 at 11:27
  • @CoolMind So what do you use it for debug vs non-debug? – android developer Sep 01 '20 at 14:51
  • 1
    @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. – CoolMind Sep 01 '20 at 14:57
  • 1
    @CoolMind 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? – android developer Sep 02 '20 at 07:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220840/discussion-between-coolmind-and-android-developer). – CoolMind Sep 02 '20 at 08:28
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
}
ConcernedHobbit
  • 764
  • 1
  • 8
  • 17
  • 1
    Thanks! I agree with you, in build configuration we can change interval to zero. – CoolMind Mar 05 '20 at 08:44
  • 1
    Agree with you, looking at https://androidwave.com/firebase-remote-config/ and https://blog.mindorks.com/getting-started-with-firebase-remote-config-in-android, I found that they also had set 0 seconds in debug build. – CoolMind Sep 02 '20 at 08:42