Android Suspicious Import

ID

kotlin.android_suspicious_import

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

android, imports, reliability

Description

Flags Kotlin import android.R or import android.R.* statements. Importing the Android framework’s android.R class instead of the application’s own generated R class causes every unqualified resource reference to silently resolve against the platform’s built-in resources rather than the app’s own. The IDE may not catch the mismatch, and the app loads the wrong drawables, strings, or layouts at runtime.

Rationale

import android.R              // FLAW
import android.R.layout       // FLAW
import android.R.string.ok    // FLAW

import com.example.app.R      // OK — the app's own R
import android.os.Bundle      // OK — unrelated android import

android.R is the resource namespace exposed by the Android system. Apps almost always want their own generated R (typically com.example.app.R). When both are in scope, an unqualified R.layout.main_layout silently picks the platform symbol, leading to runtime exceptions or wrong layouts.

Remediation

  • Delete the import android.R line.

  • Reference the app’s own R via the package-qualified name when both are needed.

  • Configure the IDE auto-import to exclude android.R from the import suggestions.