Unrecognized Attribute Name MODULE Error in Android Builds
Problem Statement
When updating Android projects to target Android 12 (API level 31) or higher, developers may encounter a build error with the message:
unrecognized Attribute name MODULE (class com.sun.tools.javac.util.SharedNameTable$NameImpl)
This error occurs during the Kotlin Annotation Processing (kapt) task and manifests as an InvocationTargetException
with the specific AssertionError
about the unrecognized MODULE attribute.
Root Cause
The error arises from a compatibility issue between:
- compileSdkVersion 31+ (Android 12 or later)
- JDK 8 (Java Development Kit version 8)
- Code containing lambda expressions or certain annotations
Android's build toolchain has evolved to require JDK 11 when targeting newer Android API levels, as the Android SDK now includes features and bytecode that are incompatible with JDK 8.
Solutions
Primary Solution: Upgrade to JDK 11
The most effective solution is to upgrade your Java Development Kit to version 11 or later.
Android Studio Configuration
// In your project's build.gradle
android {
compileSdkVersion 31
kotlin {
jvmToolchain(11) // Use JDK 11
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
kotlinOptions {
jvmTarget = '11'
}
IDE Settings
Android Studio:
- Go to
File → Project Structure → SDK Location
- Under
Gradle Settings
, setGradle JDK
to version 11 - Alternatively, use the dropdown to download JDK 11 directly
- Go to
Visual Studio (Xamarin/MAUI):
- Install JDK 11 from Microsoft's distribution
- Update path in
Tools → Android → Android SDK Manager → Locations
CI/CD and Build Server Configuration
For automated build environments, ensure JDK 11 is configured:
# Set JAVA_HOME to JDK 11 path
export JAVA_HOME=/path/to/jdk11
# For Azure AppCenter builds
environment:
JAVA_HOME: $(JAVA_HOME_11_X64)
# Docker-based builds
FROM openjdk:11-jdk
Alternative Approach: Downgrade Target SDK (Temporary Fix)
If immediate JDK upgrade isn't feasible, temporarily target Android 11:
android {
compileSdkVersion 30 // Instead of 31
// Note: This is not recommended for production long-term
}
Verifying the Solution
After making changes, verify your configuration:
- Clean your project:
./gradlew clean
- Check Java version:
java -version
(should show version 11+) - Verify Gradle JDK setting in Android Studio
- Rebuild your project
Common Pitfalls and Additional Considerations
WARNING
Multiple JDK Installations: Ensure all parts of your project use the same JDK version. Mixed versions can cause persistent issues.
WARNING
Legacy Dependencies: Some older libraries may not be compatible with JDK 11. Check for updates or alternatives.
If you continue to experience issues:
- Invalidate Caches: In Android Studio, use
File → Invalidate Caches / Restart
- Check Kotlin Version: Ensure Kotlin plugin is updated (1.7.10+ recommended)
- Review Build Scripts: Remove deprecated settings:
- Remove
jcenter()
repositories - Update Android Gradle Plugin to 7.0+
- Remove obsolete ProGuard settings
- Remove
Migration Diagram
Conclusion
The "unrecognized Attribute name MODULE" error is a clear indicator of JDK compatibility issues when targeting newer Android API levels. The definitive solution is upgrading to JDK 11 across all development and build environments. While temporary workarounds exist, keeping your toolchain updated ensures compatibility with current and future Android platform features.