kotlin:S1128 False Positive Jetpack Compose

When using the SonarLint plugin in Android Studio, it reports unused imports (kotlin:S1128) for setValue and getValue from Jetpack Compose although they are required to use state (e.g. var x by mutableStateOf(true)).



Minimal Code Sample

Create an Android app in Android Studio with Jetpack Compose (Use Android Studio with Jetpack Compose  |  Android Developers) and add the following view model:

package com.example.app.viewmodels

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel

class TestViewModel: ViewModel() {
    var isLoading by mutableStateOf(false)

Hello Tim,

Welcome to the community!

Thank you for the report. You are right, there is currently an issue with the unused imports rule, it is tracked here. We will fix it soon - if the FPs are too noisy you can disable the rule as a workaround in the meantime.

Hi Johann,

thanks for the link. It seams that I’ve missed this issue in Jira.
I’ve already disabled this rule :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.