During Android application compilation or after upgrading Android Studio, developers frequently encounter the build failure error: package android.support.v7.app does not exist accompanied by cannot resolve symbol AppCompatActivity. This build error halts compilation and prevents activity layouts from rendering in the Android Studio visual editor.

This error stems from the historical deprecation of the legacy Android Support Library (com.android.support.*) in favor of Jetpack AndroidX (androidx.*). In this article, we explain the root cause and provide step-by-step solutions for both modern AndroidX projects and legacy codebases.

Quick Migration Reference: Support Library to AndroidX

Compare legacy Android Support Library references against modern AndroidX class imports and Gradle dependencies:

  • Legacy Java Class Import: import android.support.v7.app.AppCompatActivity;

  • Modern AndroidX Import: import androidx.appcompat.app.AppCompatActivity;

  • Legacy Gradle Dependency: implementation 'com.android.support:appcompat-v7:28.0.0'

  • Modern AndroidX Dependency: implementation 'androidx.appcompat:appcompat:1.6.1'

Fixing the Error in Modern Android Projects (AndroidX)

If your project uses modern Android Studio versions (Electric Eel, Flamingo, Giraffe, or Iguana), update your app module build.gradle (or build.gradle.kts) dependencies:

app/build.gradlegroovy
dependencies {
    // Replace legacy com.android.support:appcompat-v7 with AndroidX AppCompat
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
}

Next, update Java or Kotlin activity source files to use the updated AndroidX package names:

MainActivity.javajava
package com.example.myapp;
 
// Replace: import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
 
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Enabling Jetifier and AndroidX Flags in gradle.properties

If third-party SDK dependencies in your project still reference legacy support libraries, enable automatic bytecode translation via Jetifier in gradle.properties:

gradle.propertiesproperties
# Enable AndroidX refactoring support
android.useAndroidX=true
 
# Automatically transform legacy 3rd-party dependencies to AndroidX bytecode at build time
android.enableJetifier=true

Automating Refactoring via Android Studio Menu

Android Studio provides an automated migration wizard that scans project Java/Kotlin files, XML layouts, and Gradle configurations:

  • 1. Backup your repository or commit current changes to Git.

  • 2. In Android Studio top menu, click Refactor > Migrate to AndroidX...

  • 3. Click Do Refactor in the preview window to replace all android.support.v7 occurrences automatically.

  • 4. Sync Gradle files by clicking Sync Project with Gradle Files.

Troubleshooting Remaining Build Failures

  • `compileSdkVersion` Mismatch: Ensure compileSdkVersion in build.gradle is set to API 28 or higher (e.g. compileSdk = 34). AndroidX components require SDK version 28+.

  • Mixing Support & AndroidX Libraries: Never include both com.android.support:appcompat-v7 and androidx.appcompat:appcompat in the same Gradle dependency block. Duplicate class compilation errors (Duplicate class found in modules...) will occur.

  • Missing Google Maven Repository: Verify google() is listed in your project-level build.gradle or settings.gradle repository resolution management block.