Android Studio 3.0.1添加JAX-RS后Gradle构建失败(transformClassesWithDesugarForDebug报错)
transformClassesWithDesugarForDebug Failure in Android Studio 3.0.1 (After Adding JAX-RS & New Libraries) Hey there, let’s work through this frustrating build failure you’re facing. I’ve dealt with similar Desugar-related issues back when using older Android Studio versions, so here are some actionable steps to try:
1. Verify Desugar & Java Version Configuration
Desugar handles converting Java 8+ bytecode to work on older Android devices, and Android Studio 3.0.1 has some quirks with this tool—especially when adding libraries like JAX-RS that might use Java 8 features.
First, make sure your app-level build.gradle explicitly sets Java 8 compatibility:
android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
Double-check that you haven’t mixed Java versions (e.g., setting source to 1.8 but target to 1.7) — this is a common hidden cause.
2. Hunt Down Dependency Conflicts
JAX-RS libraries often bring in transitive dependencies that clash with existing ones in your project. To diagnose this:
- Run this command in your project root to generate a full dependency tree:
# macOS/Linux ./gradlew app:dependencies # Windows gradlew.bat app:dependencies - Look for duplicate entries under
javax.ws.rsor related groups. If you find conflicts, exclude the problematic transitive dependency from your JAX-RS library. For example:implementation('com.your.jaxrs.library:your-library:1.0') { exclude group: 'javax.ws.rs', module: 'javax.ws.rs-api' }
3. Align Gradle Plugin & Gradle Versions
Android Studio 3.0.1 is designed to work with specific Gradle versions:
- The default plugin version is
com.android.tools.build:gradle:3.0.1 - Corresponding Gradle version is 4.1
Check your project-level build.gradle to confirm these match. If you’ve modified either version accidentally, revert them to the compatible pair. If you’re feeling bold, you can try upgrading to the latest patch version of the 3.0.x plugin (e.g., 3.0.2) and matching Gradle version (4.2) — this fixes some known Desugar bugs without breaking AS 3.0.1 compatibility.
4. Wipe All Caches (More Thoroughly Than Clean/Rebuild)
Sometimes the standard clean/rebuild isn’t enough to clear corrupted Desugar caches. Try these steps:
- Delete the
.gradlefolder in your project root - Delete the
buildfolder inside your app module - Go to File > Invalidate Caches / Restart in Android Studio, then select "Invalidate and Restart"
5. Ensure Your JAX-RS Library is Android-Compatible
Many JAX-RS libraries are built for Java EE environments, not Android, and may contain classes or methods that Desugar can’t process. Consider:
- Switching to an Android-optimized alternative like Retrofit (if you don’t strictly need JAX-RS compliance)
- Using a lightweight JAX-RS client that’s tested on Android, like
org.glassfish.jersey.core:jersey-clientversion 2.26 or lower (newer versions may have compatibility issues with AS 3.0.1)
If none of these steps resolve the issue, sharing your full app-level build.gradle file would help pinpoint the exact problem—there might be a specific library combination or configuration we’re missing.
内容的提问来源于stack exchange,提问作者Shankha057

