Skip to content

Updating Android Gradle Plugin for compileSdk 33

Problem Statement

When building Android applications targeting newer SDK versions, you may encounter a warning message suggesting you need a newer version of the Android Gradle Plugin (AGP):

We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.2.1) was tested up to compileSdk = 32

This warning can be suppressed by adding android.suppressUnsupportedCompileSdk=33 to this project's gradle.properties

This warning appears when your project targets a newer compileSdkVersion than what your current Android Gradle Plugin version was designed to support. While this is technically a warning and not a build error, it's strongly recommended to address it to ensure compatibility and stability.

Solution

The most comprehensive solution is to update your Android Gradle Plugin to a version that officially supports compileSdk 33.

In your project-level build.gradle file, update the AGP version:

groovy
buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:8.2.2' // Updated version
        // ... other classpath dependencies
    }
}

Current Compatible Versions

As of 2023, the following AGP versions support compileSdk 33:

  • AGP 7.3.x and later
  • AGP 8.x and later

2. Update Gradle Wrapper

Ensure your Gradle distribution version is compatible with the new AGP. Update gradle-wrapper.properties:

properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip

3. Update Module-level Build Configuration

Update your app-level build.gradle file to ensure compatibility:

groovy
android {
    compileSdk 33
    
    defaultConfig {
        targetSdk 33
        // Keep minSdk at your desired minimum
    }
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    
    kotlinOptions {
        jvmTarget = '17'
    }
}

4. Using Android Studio's Upgrade Assistant

For a more automated approach, use Android Studio's built-in tools:

  1. Open your project in Android Studio
  2. Navigate to ToolsAGP Upgrade Assistant
  3. Follow the prompts to upgrade to the latest compatible version

INFO

The AGP Upgrade Assistant will automatically update:

  • Android Gradle Plugin version
  • Gradle wrapper version
  • Necessary configuration changes
  • Compatibility settings

Alternative Approaches

If you cannot immediately update the AGP, you can temporarily suppress the warning by adding this line to your gradle.properties file:

properties
android.suppressUnsupportedCompileSdk=33

WARNING

This approach only hides the warning and doesn't resolve the underlying compatibility issue. Use this only as a temporary measure.

Check for Android Studio Updates

Ensure your Android Studio is up to date, as newer versions typically include support for the latest AGP versions:

  1. Go to HelpCheck for Updates
  2. Install any available updates
  3. Restart Android Studio

Common Issues and Solutions

Compatibility Problems

After updating AGP, you might encounter:

  1. Deprecated API usage: Newer AGP versions may deprecate certain APIs
  2. Configuration changes: Some build configuration syntax may have changed
  3. Plugin compatibility: Third-party plugins might need updates

Resolving Build Errors

If you encounter issues after updating:

  1. Check the Android Gradle Plugin release notes for breaking changes
  2. Update any third-party plugins to their latest versions
  3. Clean and rebuild your project (Build → Clean Project then Build → Rebuild Project)

Verification

After making changes, verify that:

  1. The warning no longer appears
  2. Your project builds successfully
  3. All functionality works as expected
  4. Run tests to ensure no regressions
bash
./gradlew clean
./gradlew build
./gradlew test

Best Practices

  1. Regular updates: Keep your AGP and Gradle versions updated regularly
  2. Version alignment: Ensure AGP, Gradle, and Android Studio versions are compatible
  3. Testing: Thoroughly test your app after each AGP update
  4. Backup: Always back up your project before major dependency updates

DANGER

Avoid using extremely new AGP versions in production without thorough testing, as they may introduce unexpected behavior or bugs.

By following these steps, you can resolve the compileSdk compatibility warning while maintaining a stable and up-to-date Android development environment.