【问题标题】:'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' 已弃用
【发布时间】:2019-05-21 07:52:09
【问题描述】:

将 Firebase 库升级到

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'

在同步 Gradle 时,我收到了警告:

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

在这些行中:

//Setting Developer Mode enabled to fast retrieve the values
firebaseRemoteConfig.setConfigSettings(
    FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG)
        .build())

【问题讨论】:

标签: android firebase-remote-config


【解决方案1】:

阅读setConfigSettingssetDeveloperModeEnabled后,我将代码改为:

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

升级到com.google.firebase:firebase-config:19.0.0 后,setDefaults 方法也被弃用了。将其替换为setDefaultsAsync

第一次运行应用程序时firebaseRemoteConfig 不会获取数据并将返回默认值。要获取实际值并缓存它们,请参阅Android Firebase Remote Config initial fetch does not return value

您可以使用TimeUnit.HOURS.toSeconds(12) 之类的时间来代替3600L(由@ConcernedHobbit 提议)。

【讨论】:

  • 我必须添加“新”:firebaseRemoteConfig.setConfigSettingsAsync(new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(3600L).build());
  • @CoolMind 你是怎么得到“3600L”的,我试图找出正确的间隔应该是/在开发者模式设置为启用之前。我在firebase代码中能找到的所有东西都让我相信它应该是开发模式的“0L”,但也许我在这里遗漏了一些东西? github.com/firebase/firebase-android-sdk/blob/…
  • @MartinJäkel,你知道,我没有尝试过该版本的库,但之前尝试过(在 2018 年)。因为setConfigSettingsAsync 不依赖于开发/发布模式,我们可以为两者使用一个常量(但可以使用不同的)。正如我之前了解到的,0L 不是一个好的值,因为它会导致错误。我不记得了,但可能是同步太频繁了,最终根本没有同步,或者在回调中失败而不是成功。
  • setDeveloperModeEnabledsetMinimumFetchIntervalInSeconds 到底有什么关系?它有什么作用? setMinimumFetchIntervalInSeconds 的默认值是多少?
【解决方案2】:

为了补充 CoolMind 的回答,我发现在设置最小获取间隔 (setMinimumFetchIntervalInSeconds) 时,您有(至少)两个选项。您可以按照 CoolMind 在构建 remoteConfig 对象(在 Kotlin 中)时所说的那样做:

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

或者您可以将 fetch 命令中的值设置为提供的参数。这个例子也在 Kotlin 中,我已经扩展了我的代码以尝试清楚地说明发生了什么:

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
}

【讨论】:

猜你喜欢
  • 2022-07-10
  • 2022-01-12
  • 2014-02-12
  • 1970-01-01
  • 2018-05-02
  • 2016-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多