android - 依赖项更新后,Firebase“不覆盖任何内容”
问题描述
在将依赖项更新到最新版本(核心、身份验证、数据库......)后,我们在较旧的(2018 年)生产中的 Android 应用程序中出现 500 多个错误。
例如
"Object is not abstract and does not implement abstract member @PublicApi public abstract fun onDataChange(@NonNull p0: DataSnapshot): Unit defined in com.google.firebase.database.ValueEventListener"
"Type mismatch: inferred type is String? but String was expected"
"Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type DatabaseReference?"
"Smart cast to 'String' is impossible, because 'order.locationId' is a mutable property that could have been changed by this time"
"Type inference failed: Cannot infer type parameter K in inline operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit"
....
在这个世界上,我们没有办法一行一行地删除“?” 或添加“!!” 在整个项目中,更不用说测试和推动生产更新.....
有没有办法修复它,或者我们应该坚持使用 2018 年依赖项和 SDK 27,因为,你知道,这只是谷歌的常见做法?
编辑:
对象不是抽象的,也没有实现抽象成员@PublicApi public abstract fun onCancelled(@NonNull p0: DatabaseError): Unit defined in com.google.firebase.database.ValueEventListener
private val connectionListener = object : ValueEventListener { override fun onCancelled(p0: DatabaseError?) { } override fun onDataChange(p0: DataSnapshot?) { connected = p0?.getValue(Boolean::class.java)!! if (connected) { disconnectReference?.child(resources.getString(R.string.offline))?.setValue(false) disconnectReference?.child(resources.getString(R.string.offline))?.onDisconnect()?.setValue(true) { error, _ -> if (error != null) Log.e(this@ApplicationInventoryManagement.javaClass.simpleName, resources.getString(R.string.on_disconnect_event)) } disconnectReference?.child(resources.getString(R.string.last_sync))?.onDisconnect()?.setValue(ServerValue.TIMESTAMP) } }
}
修复正在删除“?” 从被覆盖的方法参数中,在项目中的 100 多个地方都是一样的
类型推断失败:无法在内联运算符 fun MutableMap.set(key: K, value: V) 中推断类型参数 K:单位
private val productEventListener = object : EventListenerWithBroadcast() { override fun onDataChange(dataSnapshot: DataSnapshot) { productsLoaded = false val productChange = Intent(ApplicationInventoryManagement.FIREBASE_DATA_CHANGE) doAsync { dataSnapshot.children .filterNotNull() .forEach { products!![it.key] = it.getValue(Product::class.java)!! } if (sendBroadcast) { productChange.putExtra(ApplicationInventoryManagement.TYPE, ApplicationInventoryManagement.PRODUCTS) LocalBroadcastManager.getInstance(this@ActivityMain).sendBroadcast(productChange) } productsLoaded = true } } override fun onCancelled(databaseError: DatabaseError) {}
}
修复是添加'!!' 映射键 "products!![it.key!!]" 因为现在它不想为空
在 DatabaseReference 类型的可空接收器上只允许安全 (?.) 或非空断言 (!!.) 调用?
ref.parent.child("selected").setValue(false)
修复正在添加“?” 在父 "ref.parent?.child..." 之后,因为现在它希望是可空的,或者用 '!!' 断言的非空
类型不匹配:推断类型是字符串?但字符串是预期的
val key = FirebaseDatabase.getInstance().getReference(Constants.vehicles) .child(vehicleKey) .child("log") .push().key
修复是添加'!!' 在第一个子键“.child(vehicleKey!!)...”等...
解决方案
推荐阅读
- angular - 使用 RxJS ForkJoin 操作符
- java - 将表单数据作为文件 (wsdl.xml) 发布请求
- c++ - 我可以为 assert() 禁用 GCC 的 noreturn 属性吗
- javascript - 是否可以将诸如“12.13”之类的整数拆分为12和13?
- python-3.x - 如何使用python读取csv文件中特定值的特定日期和时间
- java - 为什么 Spring @Value 注解的 String 变量会得到浮点值?
- tensorflow - “操作的图表与会话的图表不同”错误
- python - 在 Python 中使用不变的 URL 进行动态 Web 抓取
- php - Codeigniter form_validations 不会显示任何 validation_errors 消息
- javascript - 防止表单的值在 onclick 事件后被重置,并将用户的输入保留在会话存储中