Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle plugin lint error when format string res

I have a string res and kotlin data class below:

<string name="amount_format">¥%1$.2f</string>

data class TagAndTotal(
    @ColumnInfo(name = "tag_name") var tagName: String,
    @ColumnInfo(name = "total") var total: Float)

I got error below when I run ./gradlew lint after I upgrade to 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))

But it's no error in AGP 3.0.1.

like image 497
littlegnal Avatar asked Dec 18 '22 00:12

littlegnal


1 Answers

I got the same problem. Declare an explicit local variable with type solve my problem.

In your case, could you try:

val total : Double = it.total
applicationContext.getString(R.string.amount_format, total)

I think this is a bug in AGP

like image 92
Kuma Avatar answered Dec 30 '22 13:12

Kuma