information

How to Fix Jetpack Compose “Cannot access class”

When building a Jetpack Compose project, Android Studio or the Kotlin compiler may report “Cannot access class”.

Cannot access class '...'. Check your module classpath for missing or conflicting dependencies.

This error does not necessarily mean that the class named in the message is broken. More commonly, a required dependency is missing, multiple incompatible versions are present, or the class exposes another type that is unavailable on the module’s compile classpath.

Kotlin examples of this error show the same pattern: a library class can be visible while one of its supertypes or dependent types is missing, leading to “Cannot access class” and “Check your module classpath for missing or conflicting dependencies.” :contentReference[oaicite:19]{index=19}

Jetpack Compose combines Runtime, UI, Foundation, Material, Activity, Lifecycle, and other AndroidX libraries, so dependency alignment is especially important.

Google’s current Android documentation recommends using the Compose BOM to align Compose library versions and, with Kotlin 2.0 or later, using the Compose Compiler Gradle plugin with the same version as Kotlin. :contentReference[oaicite:20]{index=20}

This article explains the main causes of Jetpack Compose “Cannot access class” errors and how to diagnose dependencies, modules, Kotlin, Gradle, and IDE-only problems.

  1. What Does “Cannot access class” Mean?
  2. Common Situations
  3. Cause 1: A Required Dependency Is Missing
  4. Solution 1: Read the Fully Qualified Class Name
  5. Cause 2: Compose Library Versions Are Mixed Arbitrarily
  6. Solution 2: Use the Compose BOM
  7. Cause 3: Kotlin and the Compose Compiler Configuration Are Inconsistent
  8. Solution 3: Align the Compose Compiler Plugin with Kotlin
  9. Cause 4: Compose Is Not Enabled in the Module
  10. Solution 4: Enable Compose
  11. Cause 5: A Multi-Module Dependency Is Not Exposed
  12. Solution 5: Check api vs implementation
  13. Cause 6: Transitive Dependencies Were Disabled
  14. Solution 6: Restore Transitive Dependencies
  15. Cause 7: Multiple Versions of the Same Library Are Present
  16. Solution 7: Inspect the Dependency Tree
  17. Solution 8: Use dependencyInsight
  18. Cause 8: The Test Classpath Is Missing a Dependency
  19. Solution 9: Add the Required Test Dependencies
  20. Cause 9: Only Compose Preview Fails
  21. Solution 10: Add Preview Tooling
  22. Cause 10: Activity Compose Is Missing
  23. Solution 11: Add activity-compose
  24. Cause 11: ViewModel Compose Is Missing
  25. Solution 12: Add lifecycle-viewmodel-compose
  26. Cause 12: Gradle Sync Failed
  27. Solution 13: Run Gradle Sync
  28. Cause 13: Gradle Builds but Android Studio Still Shows the Error
  29. Solution 14: Build from the Command Line
  30. Solution 15: Resynchronize Android Studio
  31. Do Not Start by Clearing Caches
  32. Cause 14: Dependencies Were Copied from an Old Compose Tutorial
  33. Cause 15: Kotlin Metadata Is Incompatible
  34. Solution 16: Read the First Compiler Error
  35. Cause 16: JVM Targets Are Inconsistent Across Modules
  36. Solution 17: Align Java/Kotlin Compilation Settings
  37. Cause 17: The Wrong Class with the Same Simple Name Is Imported
  38. Solution 18: Check Fully Qualified Imports
  39. Basic Dependency Diagnostic Commands
  40. Check CompileClasspath, Not Only RuntimeClasspath
  41. Example of a Consistent Compose Dependency Setup
  42. Basic Kotlin 2.x Plugin Setup
  43. Cannot access class vs Unresolved reference
  44. Fastest Troubleshooting Order
  45. If the Error Still Occurs
  46. Summary

What Does “Cannot access class” Mean?

A typical message looks like:

Cannot access class 'androidx.example.SomeClass'. Check your module classpath for missing or conflicting dependencies.

You may also see:

Supertypes of the following classes cannot be resolved

Unresolved supertypes

Check your module classpath for missing or conflicting dependencies

The important point is that the compiler may be able to see the API you are calling but still be unable to resolve a parameter type, return type, supertype, or transitive dependency used by that API.

Key point: “Cannot access class” is usually a classpath/dependency problem rather than a simple missing import.

Common Situations

  • After updating Compose libraries
  • After updating Kotlin
  • After removing the Compose BOM
  • After manually changing only one Compose library version
  • After copying Compose code from another project
  • After converting the project to multiple modules
  • After moving Compose code into another module
  • When Activity Compose or Lifecycle Compose is missing
  • When application builds work but tests fail
  • When only Android Studio shows the error
  • When Gradle builds successfully but IDE analysis fails

Cause 1: A Required Dependency Is Missing

This is the most fundamental cause.

Suppose library A exposes an API whose return type comes from library B. If B is missing from your compile classpath, the A API may still be visible, but Kotlin cannot resolve its type.

The result can be:

Cannot access class 'library.b.SomeType'

Solution 1: Read the Fully Qualified Class Name

For example, if the error names an AndroidX Lifecycle class, verify that the corresponding Lifecycle dependency is present.

Common Compose-related artifacts include:

androidx.compose.runtime:runtime androidx.compose.ui:ui androidx.compose.foundation:foundation androidx.compose.material3:material3 androidx.activity:activity-compose androidx.lifecycle:lifecycle-viewmodel-compose

Google’s current Compose setup page lists Activity Compose and Lifecycle ViewModel Compose as separate optional integration dependencies. :contentReference[oaicite:21]{index=21}

Cause 2: Compose Library Versions Are Mixed Arbitrarily

A configuration such as:

implementation( "androidx.compose.ui:ui:1.10.0" )

implementation(
"androidx.compose.foundation:foundation:1.8.0"
)

implementation(
"androidx.compose.runtime:runtime:1.12.0"
)

can create compatibility problems.

Solution 2: Use the Compose BOM

Google’s current setup documentation recommends the Compose BOM. As of September 2026, the official setup page lists Compose BOM 2026.08.00. :contentReference[oaicite:22]{index=22}

dependencies { val composeBom = platform( "androidx.compose:compose-bom:2026.08.00" )
implementation(composeBom)
androidTestImplementation(composeBom)

implementation(
    "androidx.compose.ui:ui"
)

implementation(
    "androidx.compose.foundation:foundation"
)

implementation(
    "androidx.compose.material3:material3"
)

}

For BOM-managed Compose libraries, avoid manually specifying unrelated individual versions.

Important: The Compose BOM aligns Compose libraries. It does not set the Kotlin version.

Cause 3: Kotlin and the Compose Compiler Configuration Are Inconsistent

Even if Runtime and UI dependencies are present, an incorrect Compose compiler setup can lead to broader compilation failures.

For Kotlin 2.0 and later, Google currently recommends the Compose Compiler Gradle plugin:

org.jetbrains.kotlin.plugin.compose

using the same version as Kotlin. :contentReference[oaicite:23]{index=23}

Solution 3: Align the Compose Compiler Plugin with Kotlin

libs.versions.toml:

[versions] kotlin = "2.3.21"

[plugins]
kotlin-android = {
id = "org.jetbrains.kotlin.android",
version.ref = "kotlin"
}

compose-compiler = {
id = "org.jetbrains.kotlin.plugin.compose",
version.ref = "kotlin"
}

Module:

plugins { alias( libs.plugins.kotlin.android )
alias(
    libs.plugins.compose.compiler
)

}

Google’s current documentation says to apply the Compose Compiler plugin to each module that uses Compose. :contentReference[oaicite:24]{index=24}

Cause 4: Compose Is Not Enabled in the Module

If Compose code was moved to another Android module, that module may not have Compose enabled.

Solution 4: Enable Compose

android { buildFeatures { compose = true } }

This remains part of Google’s current Compose setup. :contentReference[oaicite:25]{index=25}

Cause 5: A Multi-Module Dependency Is Not Exposed

Consider:

:app ↓ :feature-home ↓ :core-ui

If :feature-home publicly exposes types from :core-ui, but that dependency is hidden from consumers, downstream code can fail to resolve those types.

Solution 5: Check api vs implementation

For a dependency whose types are part of the module’s public API:

dependencies { api( project(":core-ui") ) }

Use api only when consumers genuinely need to see that dependency’s types.

Cause 6: Transitive Dependencies Were Disabled

For example:

implementation("example:library:1.0") { isTransitive = false }

This can remove required child dependencies from the classpath.

Solution 6: Restore Transitive Dependencies

implementation( "example:library:1.0" )

If you disabled transitive dependencies intentionally, verify every dependency that must now be added manually.

Cause 7: Multiple Versions of the Same Library Are Present

For example:

Library A → Lifecycle 2.8.x

Library B
→ Lifecycle 2.10.x

You need to see which version Gradle actually selected.

Solution 7: Inspect the Dependency Tree

macOS or Linux:

./gradlew :app:dependencies

Windows:

gradlew.bat :app:dependencies

For a specific configuration:

./gradlew :app:dependencies \ --configuration debugRuntimeClasspath

Solution 8: Use dependencyInsight

./gradlew :app:dependencyInsight \ --dependency androidx.compose.runtime \ --configuration debugRuntimeClasspath

For Lifecycle:

./gradlew :app:dependencyInsight \ --dependency androidx.lifecycle \ --configuration debugRuntimeClasspath

This shows why a dependency is present and which version was selected.

Cause 8: The Test Classpath Is Missing a Dependency

The app may build normally while tests fail with:

Cannot access class ...

Check:

implementation testImplementation androidTestImplementation

Kotlin community examples show the same classpath error when test source sets cannot access required dependencies. :contentReference[oaicite:26]{index=26}

Solution 9: Add the Required Test Dependencies

dependencies { testImplementation( "junit:junit:4.13.2" )
androidTestImplementation(
    platform(
        "androidx.compose:compose-bom:2026.08.00"
    )
)

androidTestImplementation(
    "androidx.compose.ui:ui-test-junit4"
)

}

Cause 9: Only Compose Preview Fails

If the app builds but Preview fails, verify the tooling dependencies.

Solution 10: Add Preview Tooling

dependencies { implementation( "androidx.compose.ui:ui-tooling-preview" )
debugImplementation(
    "androidx.compose.ui:ui-tooling"
)

}

Google’s current Compose setup page includes this Preview configuration. :contentReference[oaicite:27]{index=27}

Cause 10: Activity Compose Is Missing

If Activity-related Compose types cannot be accessed, check Activity Compose.

Solution 11: Add activity-compose

dependencies { implementation( "androidx.activity:activity-compose:1.13.0" ) }

Google’s official Compose setup page lists activity-compose:1.13.0 as the Activity integration example in September 2026. :contentReference[oaicite:28]{index=28}

Cause 11: ViewModel Compose Is Missing

Compose ViewModel APIs such as:

viewModel()

may require the Lifecycle ViewModel Compose integration.

Solution 12: Add lifecycle-viewmodel-compose

dependencies { implementation( "androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0" ) }

Google’s September 2026 Compose setup page lists lifecycle-viewmodel-compose:2.10.0 for ViewModel integration. :contentReference[oaicite:29]{index=29}

Cause 12: Gradle Sync Failed

Correct source code cannot resolve dependencies if Gradle has not successfully loaded them.

Solution 13: Run Gradle Sync

File → Sync Project with Gradle Files

Fix any earlier errors such as:

  • Could not resolve
  • Plugin not found
  • Repository errors
  • Version conflicts

Cause 13: Gradle Builds but Android Studio Still Shows the Error

This can be an IDE-only problem.

Kotlin community reports describe situations where Gradle and the Kotlin compiler successfully build the project while Android Studio still highlights code with “Cannot access class.” :contentReference[oaicite:30]{index=30}

Important: Determine whether the command-line build actually fails before changing dependencies.

Solution 14: Build from the Command Line

macOS or Linux:

./gradlew assembleDebug

Windows:

gradlew.bat assembleDebug

If this succeeds, the source code and Gradle classpath may be correct and the issue may be limited to the IDE project model.

Solution 15: Resynchronize Android Studio

Try this order:

  1. Gradle Sync
  2. Build → Rebuild Project
  3. Restart Android Studio

Only consider invalidating caches after confirming that the Gradle build is healthy.

Do Not Start by Clearing Caches

A better diagnostic order is:

1. Gradle build 2. dependencies 3. dependencyInsight 4. Compose BOM 5. Kotlin / Compose Compiler 6. Gradle Sync 7. IDE restart 8. Cache reset if still necessary

Clearing caches does not fix a truly missing compile dependency.

Cause 14: Dependencies Were Copied from an Old Compose Tutorial

Compose build configuration has changed over time.

Google’s current documentation uses the Kotlin Compose Compiler Gradle plugin for Kotlin 2.0+, and the current setup page lists Kotlin 2.3.21 in its example and Compose BOM 2026.08.00. :contentReference[oaicite:31]{index=31}

Review old settings such as:

kotlinCompilerExtensionVersion old Compose UI versions old Activity Compose versions

Cause 15: Kotlin Metadata Is Incompatible

A dependency compiled with a much newer Kotlin version can also cause metadata errors that appear alongside class-access failures.

Look for messages such as:

Module was compiled with an incompatible version of Kotlin

The binary version of its metadata is ...

Solution 16: Read the First Compiler Error

Do not focus only on the final “Cannot access class” line.

The first error may directly identify:

Missing dependency Version conflict Kotlin metadata incompatibility

Cause 16: JVM Targets Are Inconsistent Across Modules

Large differences in Java or Kotlin compilation targets can contribute to multi-module build failures.

Solution 17: Align Java/Kotlin Compilation Settings

android { compileOptions { sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility =
        JavaVersion.VERSION_17
}

}

Keep the Kotlin JVM target consistent with the project’s supported toolchain as well.

Cause 17: The Wrong Class with the Same Simple Name Is Imported

Sometimes the problem is not a missing dependency but the wrong type.

For example:

android.app.Fragment

androidx.fragment.app.Fragment

Kotlin community troubleshooting also recommends checking fully qualified class names when seemingly identical classes do not match. :contentReference[oaicite:32]{index=32}

Solution 18: Check Fully Qualified Imports

import androidx.fragment.app.Fragment

Verify every ambiguous type in the failing API call.

Basic Dependency Diagnostic Commands

./gradlew :app:dependencies

Then inspect a specific dependency:

./gradlew :app:dependencyInsight \ --dependency compose \ --configuration debugCompileClasspath

Check CompileClasspath, Not Only RuntimeClasspath

Because “Cannot access class” is usually a compile-time problem, inspect:

debugCompileClasspath

with:

./gradlew :app:dependencies \ --configuration debugCompileClasspath

Example of a Consistent Compose Dependency Setup

android { buildFeatures { compose = true } }

dependencies {
val composeBom =
platform(
"androidx.compose:compose-bom:2026.08.00"
)

implementation(composeBom)

implementation(
    "androidx.compose.ui:ui"
)

implementation(
    "androidx.compose.foundation:foundation"
)

implementation(
    "androidx.compose.material3:material3"
)

implementation(
    "androidx.activity:activity-compose:1.13.0"
)

implementation(
    "androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0"
)

}

This follows the dependency structure shown in Google’s current Compose setup documentation. :contentReference[oaicite:33]{index=33}

Basic Kotlin 2.x Plugin Setup

plugins { id("org.jetbrains.kotlin.android") id("org.jetbrains.kotlin.plugin.compose") }

The modern Compose Compiler plugin should use the same version as Kotlin. :contentReference[oaicite:34]{index=34}

Cannot access class vs Unresolved reference

Unresolved reference often means that the declaration itself cannot be found.

By contrast:

Cannot access class 'X'

often means that the compiler can see the API but cannot resolve one of the types used by that API.

API is visible ↓ Return type / parameter / supertype is missing ↓ Cannot access class

Fastest Troubleshooting Order

  1. Read the fully qualified class name in the error.
  2. Run ./gradlew assembleDebug.
  3. Inspect debugCompileClasspath.
  4. Use dependencyInsight for the affected library.
  5. Verify that the project uses the Compose BOM.
  6. For Kotlin 2.x, verify the Compose Compiler plugin.
  7. Confirm that Compose is enabled in the affected module.
  8. In multi-module projects, check api versus implementation.
  9. Run Gradle Sync.
  10. If Gradle succeeds, investigate Android Studio’s project model instead.

If the Error Still Occurs

Check all of the following:

  • The dependency containing the named class is present.
  • Compose Runtime, UI, Foundation, and Material versions are not manually mixed.
  • The Compose BOM is configured.
  • Kotlin and the Compose Compiler plugin are configured correctly.
  • Compose is enabled in the module containing the source file.
  • Required multi-module dependencies are exposed correctly.
  • isTransitive = false is not removing required libraries.
  • Test source sets have the dependencies they need.
  • Activity Compose or Lifecycle Compose is not missing.
  • Multiple AndroidX versions are not conflicting.
  • A Kotlin metadata error does not appear earlier in the log.
  • The wrong class with the same simple name is not imported.
  • The command-line Gradle build also fails.
  • The problem is not limited to Android Studio analysis.

Summary

Jetpack Compose “Cannot access class” usually means that a type required by an API is missing from the module’s compile classpath or a dependency/version conflict prevents Kotlin from resolving it correctly.

Start by reading the full class name:

Cannot access class '...'. Check your module classpath for missing or conflicting dependencies.

Then inspect the actual compile classpath:

./gradlew :app:dependencies \ --configuration debugCompileClasspath

For one dependency:

./gradlew :app:dependencyInsight \ --dependency androidx.compose \ --configuration debugCompileClasspath

For Compose dependencies, use the Compose BOM instead of manually mixing library versions. Google’s September 2026 setup page lists Compose BOM 2026.08.00. :contentReference[oaicite:35]{index=35}

For Kotlin 2.0 and later, use org.jetbrains.kotlin.plugin.compose with the same version as Kotlin and apply it to modules that use Compose. :contentReference[oaicite:36]{index=36}

If the Gradle command-line build succeeds while Android Studio alone reports “Cannot access class,” the dependency graph may already be correct and the issue may instead be limited to IDE analysis. Kotlin community reports document this exact type of IDE-only behavior. :contentReference[oaicite:37]{index=37}

The fastest strategy is therefore to first determine whether Gradle also fails. If it does, fix the classpath and dependencies. If it does not, resynchronize Android Studio before changing working dependency versions.