依赖关系更新后,Firebase“不覆盖任何内容”

时间:2019-02-25 09:38:20

标签: android firebase gradle dependencies

在依赖项更新到最新版本(核心,身份验证,数据库...)之后,我们在较旧的(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,因为,这只是Google的常见事情

编辑:

  • 对象不是抽象对象,并且未实现抽象成员@PublicApi公共抽象乐趣onCancelled(@NonNull p0:DatabaseError):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):Unit

    中推断类型参数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 ...”之后,因为它现在想成为可空值,或者使用'!!'声明为非空值。

  • 类型不匹配:推断的类型为String?但应该是String

                    val key = FirebaseDatabase.getInstance().getReference(Constants.vehicles)
                        .child(vehicleKey)
                        .child("log")
                        .push().key
    

修复程序添加了“ !!”在第一个子键“ .child(vehicleKey !!)...”上,依此类推...

0 个答案:

没有答案