Modernizing Your Android Build Pipeline
With the release of Kotlin 2.0 (K2 compiler) and recent Android Studio versions, Android build pipelines have evolved significantly. Many Capacitor developers encounter Namespace not specified errors or Java 21 compatibility conflicts.
4-Step Upgrade Guide
1. Update the Gradle Wrapper
In android/gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-8.9-all.zip
2. Configure Android Gradle Plugin (AGP)
In android/build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:8.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
}
3. Set Java 17 / Java 21 Compatibility
In android/app/build.gradle:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
}
4. Clean and Sync Project
Run in your terminal:
cd android
./gradlew clean