Android Invalid Import

ID

kotlin.android_invalid_import

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Best Practice

Language

Kotlin

Tags

android, best-practice, deprecated

Description

Reports import headers whose path matches a configurable forbidden list. The default configuration targets two well-known deprecated Android package families:

  • android.support.* — the original Android Support Library was replaced by AndroidX in 2018; new code referencing it pulls in a library that no longer receives releases.

  • kotlinx.android.synthetic.* — the Kotlin Android Extensions synthetic-import mechanism was deprecated in Kotlin 1.4.20 and later removed.

Rationale

import android.support.v4.app.Fragment            // FLAW — use androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.activity.*  // FLAW — use ViewBinding

import androidx.fragment.app.Fragment             // OK

Forbidden imports leak deprecated APIs into new code, accumulate technical debt, and prevent projects from picking up bug fixes shipped only in the modern replacement.

Remediation

  • For android.support., migrate to the corresponding androidx. package (most names map directly).

  • For kotlinx.android.synthetic.*, generate a ViewBinding or DataBinding class and access views through the binding instance.

  • Add or remove entries via the forbidden YAML property; entries ending in . are matched as package prefixes, others must be exact import paths.