Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated

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())
like image 701
CoolMind Avatar asked May 21 '19 07:05

CoolMind


2 Answers

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

like image 144
CoolMind Avatar answered Oct 19 '22 06:10

CoolMind


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
}
like image 43
ConcernedHobbit Avatar answered Oct 19 '22 05:10

ConcernedHobbit