在使用./gradlew build
编译项目时候遇到了该问题,整体错误如下:
* What went wrong:
Configuration cache state could not be cached: field `generatedModuleFile` of `com.android.build.gradle.tasks.JdkImageInput` bean found in field `compilerArgumentProviders` of `org.gradle.api.tasks.compile.CompileOptions` bean found in field `capturedArgs` of `java.lang.invoke.SerializedLambda` bean found in field `spec` of `org.gradle.api.internal.tasks.execution.SelfDescribingSpec` bean found in task `:app:compileDebugJavaWithJavac` of type `org.gradle.api.tasks.compile.JavaCompile`: error writing value of type 'org.gradle.api.internal.provider.TransformBackedProvider'
> Could not resolve all files for configuration ':app:androidJdkImage'.
> Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JdkImageTransform: /Users/ym/Work/AndroidDevelop/AndroidSdk/platforms/android-34/core-for-system-modules.jar.
> Error while executing process /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin/jlink with arguments {--module-path /Users/ym/.gradle/caches/transforms-3/9238aeceb3486cd22cebc21db321c758/transformed/output/temp/jmod --add-modules java.base --output /Users/ym/.gradle/caches/transforms-3/9238aeceb3486cd22cebc21db321c758/transformed/output/jdkImage --disable-plugin system-modules}
可以看出使用的sdk版本为34,java版本为21.
解决办法为,修改java版本为17。本地重新下载Java17的jdk,这样本地就会有21、17两个版本,然后在项目中指定依赖的java版本17并配置路径(也可以配置环境变量)
gradle.properties
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
该问题仅仅通过修改编译版本或者下载ndk无法解决