我在下面有一个字符串 res 和 kotlin 数据类:
<string name="amount_format">¥%1$.2f</string>
data class TagAndTotal(
@ColumnInfo(name = "tag_name") var tagName: String,
@ColumnInfo(name = "total") var total: Float)
当我运行 ./gradlew lint
时出现以下错误在我升级到 AGP 3.1.0 之后。
Error: Wrong argument type for formatting argument '#1' in
amount_format: conversion is 'f', received <ErrorType> (argument #2 in
method call) [StringFormatMatches]
applicationContext.getString(R.string.amount_format, it.total))
但在 AGP 3.0.1 中没有错误。
最佳答案
我遇到了同样的问题。声明一个具有类型的显式局部变量解决了我的问题。
在您的情况下,您可以尝试:
val total : Double = it.total
applicationContext.getString(R.string.amount_format, total)
我认为这是 AGP 中的一个错误
关于android - 格式化字符串 res 时 gradle 插件 lint 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49692633/