Cannot resolve symbol 'AppCompatActivity'
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Cannot resolve symbol 'AppCompatActivity' means the project cannot see the AndroidX AppCompat library or the import path is wrong. In modern Android projects, AppCompatActivity comes from AndroidX, not from the old support libraries.
So the fix is usually one of three things: add the correct dependency, migrate to AndroidX, or correct the import statement. The class itself is not missing from Android development in general. It is missing from your current module setup.
The Correct Import
The modern import is:
If your file still imports an old support-library path such as android.support.v7.app.AppCompatActivity, the project is probably half-migrated.
Add the Dependency
Your app module needs the AppCompat dependency:
After changing Gradle files, sync the project so Android Studio downloads and indexes the dependency.
Make Sure AndroidX Is Enabled
In gradle.properties, modern projects usually need:
If you migrated from an older project, missing these flags can leave the codebase in an inconsistent state where AndroidX classes are expected in source code but not handled consistently in the build.
Check the Module and Package Imports Together
This error is often half dependency issue and half source-file issue. A correct Gradle file will not help if the source still imports the old package, and a correct import will not help if the module that contains the activity does not depend on AppCompat. That is why checking only one side of the problem often wastes time.
A Minimal Working Activity
If this still fails to resolve, the problem is not the activity source code. It is the module configuration or dependency state.
Project Sync and Cache Problems
Sometimes the Gradle configuration is correct, but Android Studio has not synced cleanly. In that case:
- sync Gradle again
- rebuild the project
- invalidate caches only if the configuration is already correct
Do not start with cache invalidation. Fix the dependency and import path first.
Legacy Support Libraries
If you are maintaining an old support-library project, the more durable answer is migration to AndroidX. Mixing old android.support.* references with new androidx.* dependencies causes exactly the kind of symbol-resolution confusion that shows up here.
Android Studio's migration tool can help, but you still need to inspect the result afterward.
Build Script Example
A minimal modern module configuration usually includes something like:
If the module uses a different Gradle file or is not the app module you think you are editing, the dependency can look correct in one place while remaining absent in the module that actually owns the activity source.
Common Pitfalls
- Using the old support-library import with a modern AndroidX project.
- Adding the dependency in the wrong Gradle module.
- Forgetting to sync after editing Gradle files.
- Assuming IDE cache corruption before checking the actual dependency configuration.
- Leaving the project half-migrated between support libraries and AndroidX.
Summary
- '
AppCompatActivityshould come fromandroidx.appcompat.app.AppCompatActivity.' - Add the AndroidX AppCompat dependency to the app module.
- Make sure AndroidX is enabled in project configuration.
- Sync Gradle after changing dependencies.
- If the symbol still fails, inspect migration consistency before blaming the IDE.

