If you’re building an Android app and encounter a Gradle error like:
Execution failed for task ':app:javaPreCompileDebug'.
> Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Failed to transform artifact 'retrofit.jar'...
> Reason: Unsupported class file major version 58.
Don’t worry — you’re not alone. This issue typically occurs due to Java version incompatibility between your build tools and one of the libraries (like Retrofit or OkHttp) in your project.
In this comprehensive article, we’ll walk through why this error happens, and step-by-step solutions to resolve it.
🔍 What Does “Unsupported Class File Major Version 58” Mean?
Each Java version produces bytecode that corresponds to a class file version:
| Java Version | Class File Version |
|---|---|
| Java 8 | 52 |
| Java 11 | 55 |
| Java 14 | 58 |
| Java 17 | 61 |
So if you see major version 58, that means the .jar file was compiled using Java 14.
But Android Gradle Plugin (AGP) might only support up to Java 11, or even Java 8 if you’re using an older AGP version.
⚠️ Why This Error Happens in Android Projects
You’ll typically see this error when:
- A third-party library (like Retrofit) is compiled with Java 14.
- Your Gradle/AGP version is too old to support Java 14.
- Your Java JDK is newer than the one supported by Android Studio or AGP.
Jetifier tries to “rewrite” Java bytecode to AndroidX-compatible code. If the bytecode uses a class file version that Jetifier doesn’t support, it fails.
✅ Step-by-Step Fix
1. Use a Compatible JDK Version
Make sure you’re using JDK 11 or JDK 17 — not JDK 14.
How to check:
java -version
If it’s showing Java 14, switch to JDK 11 or 17.
For Android Studio:
- Go to
File > Project Structure > SDK Location - Set the JDK path to a valid JDK 11 or 17
2. Update Android Gradle Plugin (AGP) and Gradle
Modern libraries may require AGP 7.0+.
Update in build.gradle (Project):
classpath 'com.android.tools.build:gradle:8.0.2'
Update in gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
3. Update Your Dependencies
Use recent, compatible versions of libraries:
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
implementation 'com.squareup.retrofit2:retrofit:2.11.0'
implementation 'com.squareup.retrofit2:converter-gson:2.11.0'
⚠️ If Retrofit 2.11.0 causes the issue, try downgrading temporarily to 2.10.0 or using OkHttp 4.x instead of 3.x.
4. Clean and Rebuild the Project
./gradlew clean build
Or from Android Studio:
Build > Clean ProjectBuild > Rebuild Project
5. Disable Jetifier (if possible)
If your project and all dependencies are migrated to AndroidX, disable Jetifier:
In gradle.properties:
android.useAndroidX=true
android.enableJetifier=false
Disabling Jetifier avoids Jetifier’s transformation failures.
6. Check Local JARs or Custom Modules
If you include .jar files directly or use project(path: ...) modules, make sure those aren’t compiled with Java 14+.
Recompile those modules with Java 8 or 11 if needed:
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
💡 Summary
| Problem | Solution |
|---|---|
| Using JDK 14+ | Downgrade to JDK 11 or 17 |
| AGP too old | Update to 8.0+ |
| Incompatible dependencies | Use updated versions |
| Jetifier fails | Disable it if safe |
| Custom libraries compiled with Java 14 | Recompile them with Java 11 or lower |
📘 Bonus: Example Working Setup
android {
compileSdk 34
defaultConfig {
minSdk 21
targetSdk 34
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
In gradle.properties:
android.useAndroidX=true
android.enableJetifier=false
🏁 Conclusion
The “Unsupported class file major version 58” error means you have a mismatch between your Java version and what Android supports. By aligning your JDK, Gradle plugin, and dependencies properly, you can fix the issue and avoid build-time headaches.


