错误记录Android Studio 编译报错 ( The dependency contains Java 8 bytecode. Please enable desugaring by )

Posted 韩曙亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误记录Android Studio 编译报错 ( The dependency contains Java 8 bytecode. Please enable desugaring by )相关的知识,希望对你有一定的参考价值。

文章目录





一、报错信息



在 Android Studio 中编译工程时报如下错误信息 :

AGPBI: "kind":"error","text":"Invoke-customs are only supported starting with android O (--min-api 26)","sources":[],"tool":"D8"
AGPBI: "kind":"error","text":"Static interface methods are only supported starting with Android N (--min-api 24): Landroidx/constraintlayout/core/motion/utils/TypedValues$Attributes;getId(Ljava/lang/String;)I","sources":[],"tool":"D8"

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform constraintlayout-2.1.0.aar (androidx.constraintlayout:constraintlayout:2.1.0) to match attributes artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=false, dexing-incremental-transform=true, dexing-is-debuggable=true, dexing-min-sdk=18, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime.
      > Execution failed for DexingNoClasspathTransform: C:\\Users\\octop\\.gradle\\caches\\transforms-2\\files-2.1\\fe17b6099b802ba9bf740bdfca370160\\constraintlayout-2.1.0-runtime.jar.
         > 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.

   > Failed to transform constraintlayout-core-1.0.0.jar (androidx.constraintlayout:constraintlayout-core:1.0.0) to match attributes artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=false, dexing-incremental-transform=true, dexing-is-debuggable=true, dexing-min-sdk=18, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=8, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime.
      > Execution failed for DexingNoClasspathTransform: C:\\Users\\octop\\.gradle\\caches\\modules-2\\files-2.1\\androidx.constraintlayout\\constraintlayout-core\\1.0.0\\3b64bb29201ac1b5cb418bee55e9ae3d7940486\\constraintlayout-core-1.0.0.jar.
         > 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 24 or above.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 25s
55 actionable tasks: 3 executed, 52 up-to-date





二、解决方案



上述报错是由于在 主应用 中 , 设置的 Java 版本为 1.7 1.7 1.7 版本 , 但是在依赖库 " constraintlayout-core-1.0.0.jar " 中 , 使用的 Java 版本是 1.8 1.8 1.8 版本 , 因此报错 ;

这里按照 错误提示中的修改方法 , 将 " build.gradle # android # compileOptions " 中的 sourceCompatibility 和 targetCompatibility 属性修改为 1.8 1.8 1.8 即可 ;

           android 
               compileOptions 
                   sourceCompatibility 1.8
                   targetCompatibility 1.8
               
           

也可以写成如下形式 ;

android 
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    

以上是关于错误记录Android Studio 编译报错 ( The dependency contains Java 8 bytecode. Please enable desugaring by )的主要内容,如果未能解决你的问题,请参考以下文章

错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段

错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段

错误记录Android Studio 编译时 Kotlin 代码编译报错 ( 升级支持库时处理 @NonNull 参数 )

错误记录Android Studio 编译报错 ( Invalid main APK outputs : EarlySyncBuildOutput )

错误记录Android Studio 编译报错 ( Invalid Gradle JDK configuration found )

错误记录Android Studio 编译报错 ( VirtualApp 编译 NDK 报错 | Error:A problem occurred configuring project ‘: )(代