android - 格式化字符串 res 时 gradle 插件 lint 错误

标签 android android-gradle-plugin lint

我在下面有一个字符串 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/

相关文章:

android - 应用高于一切

android - 使用存储在数据库中的路径显示 imageview

java - AndroidStudio 3.0.1 中的 DialogFragment getActivity() "might be null"lint 警告

lint - Bazel 跳棋支持

android - Sonar 运行器 : Unable to find file warning

Android WebView - Flash swf 播放,可以听到音频,但屏幕是空白的

android - 默认 Android 12 相机,对所有文件没有访问管理 ResultCode 始终为 0

android-gradle-plugin - 合并 Android 单元测试和连接测试代码覆盖率数据已损坏

android - NoClassDefFoundError android/support/v4/animation/AnimatorCompatHelper

android - 在 Gradle 中,是否可以基于其他构建配置字段创建 bool 构建配置字段?