項目編譯報錯:
What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process F:\project\work\AppFleet_Android\app\build\intermediates\transforms\proguard\debug\0.jar
項目中出現了這個問題,查看詳細報錯信息
gradlew clean build --stacktrace
報錯信息中有一段如下:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process F:\project\work\AppFleet_Android\app\build\intermediates\transforms\proguard\debug\0.jar
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:805)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$8(DexArchiveBuilderTransform.java:730)
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
See https://developer.android.com/studio/write/java8-support.html for details. Alternatively, increase the minSdkVersion to 26 or above.
解決方案:
在app的build.gradle中android節點下增加如下配置:
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}