PC パソコン

How to Fix “Lint treats imported Java library as Android project”

If Android Lint treats an imported plain Java library as an Android project and appears to ignore the configured compileSdk, the project may be affected by a known AGP bug. Google lists Issue #404190661 as fixed in AGP 9.3.0-alpha12; upgrading to stable AGP 9.3.0 or newer is the primary fix.

What happens

Lint treats imported Java library as Android project,
ignoring compile SDK version

In configurations where both the Android project and Java library use com.android.lint, Lint could misclassify the JVM library as an Android module and perform API analysis under the wrong SDK assumptions. The reported issue can therefore disagree with the actual Android build configuration.

When this fix applies

  • An Android app or library depends on a plain Java library.
  • The Java library also configures Lint.
  • The failure occurs during Lint rather than compilation.
  • API-level analysis does not match the Android module’s compileSdk.
  • The build uses an affected AGP version older than the 9.3.0-alpha12 fix.

A genuinely old compileSdk or direct Android API use from the Java library may produce a valid warning. Confirm the module type and dependency code before classifying the result as a false positive.

Recommended fix

1. Verify the plugins applied to each module

A plain JVM library normally uses Java or Kotlin JVM plugins without an Android plugin.

plugins {
    id("java-library")
    id("com.android.lint")
}

If the module uses Android APIs, configure it as an Android library with com.android.library and an explicit compileSdk.

2. Upgrade to stable AGP 9.3.0 or newer

The AGP 9.3 release notes list Issue #404190661 as fixed in 9.3.0-alpha12, with the fix included in stable 9.3.0. Use a suitable stable 9.3.x or newer version.

plugins {
    id("com.android.application") version "9.3.0" apply false
    id("com.android.library") version "9.3.0" apply false
    id("com.android.lint") version "9.3.0" apply false
}

AGP 9.3.0 requires Gradle 9.5.0, SDK Build Tools 36.0.0, and JDK 17. Keep the Android and Lint plugin versions aligned.

3. Run the tasks separately

./gradlew clean
./gradlew :javaLibrary:lint
./gradlew :app:lintDebug --stacktrace

This separates the library analysis from the Android variant and shows which task selected the wrong SDK. Review stale baseline entries after upgrading.

Alternatives when upgrading is blocked

  • Run JVM-library and Android Lint tasks separately in CI.
  • Temporarily remove com.android.lint from the Java library if it is not needed.
  • Suppress only the confirmed false-positive issue and document why.
  • Return temporarily to a verified unaffected AGP release.

Do not broadly disable Lint or set every task to ignore errors. That can conceal real Android compatibility problems.

How to verify

  1. The Java library’s Lint task completes as a JVM-module analysis.
  2. Android Lint uses the configured compileSdk.
  3. The false API warning disappears while valid findings remain.
  4. CI produces the same result from a clean checkout.

Important notes

Regenerating a baseline alone does not correct module misclassification. Upgrade and stabilize the analysis first, then review the baseline diff.

Summary

The Lint bug that classified an imported Java library as an Android project was fixed in AGP 9.3.0-alpha12 and included in stable 9.3.0. Confirm the module’s plugins, align AGP and Lint versions, and validate the JVM and Android Lint tasks independently.

References