Gradle 构建失败,出现 sun.awt.X11GraphicsEnvironment 的 NoClassDefFoundError in :mergeDebugResources

Gradle build fails with NoClassDefFoundError for sun.awt.X11GraphicsEnvironment in :mergeDebugResources

我尝试构建时总是遇到此错误 microG:

$ ./gradlew build
Skipping debug jar:microg-ui-tools:preBuild UP-TO-DATE
:microg-ui-tools:preDebugBuild UP-TO-DATE
:microg-ui-tools:checkDebugManifest
:microg-ui-tools:preDebugAndroidTestBuild UP-TO-DATE
:microg-ui-tools:preDebugUnitTestBuild UP-TO-DATE
:microg-ui-tools:preReleaseBuild UP-TO-DATE
:microg-ui-tools:preReleaseUnitTestBuild UP-TO-DATE
:microg-ui-tools:prepareComAndroidSupportAnimatedVectorDrawable2531Library
:microg-ui-tools:prepareComAndroidSupportAppcompatV72531Library
:microg-ui-tools:prepareComAndroidSupportPreferenceV142531Library
:microg-ui-tools:prepareComAndroidSupportPreferenceV72531Library
:microg-ui-tools:prepareComAndroidSupportRecyclerviewV72531Library
:microg-ui-tools:prepareComAndroidSupportSupportCompat2531Library
:microg-ui-tools:prepareComAndroidSupportSupportCoreUi2531Library
:microg-ui-tools:prepareComAndroidSupportSupportCoreUtils2531Library
:microg-ui-tools:prepareComAndroidSupportSupportFragment2531Library
:microg-ui-tools:prepareComAndroidSupportSupportMediaCompat2531Library
:microg-ui-tools:prepareComAndroidSupportSupportV42531Library
:microg-ui-tools:prepareComAndroidSupportSupportVectorDrawable2531Library
:microg-ui-tools:prepareComTakisoftFixPreferenceV725310Library
:microg-ui-tools:prepareDebugDependencies
:microg-ui-tools:compileDebugAidl UP-TO-DATE
:microg-ui-tools:compileDebugNdk UP-TO-DATE
:microg-ui-tools:compileLint UP-TO-DATE
:microg-ui-tools:copyDebugLint UP-TO-DATE
:microg-ui-tools:compileDebugRenderscript UP-TO-DATE
:microg-ui-tools:generateDebugBuildConfig UP-TO-DATE
:microg-ui-tools:generateDebugResValues UP-TO-DATE
:microg-ui-tools:generateDebugResources UP-TO-DATE
:microg-ui-tools:mergeDebugResources
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
:microg-ui-tools:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':microg-ui-tools:mergeDebugResources'.
> java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

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

BUILD FAILED

Total time: 2.932 secs

这是在甚至没有安装 X 服务器的无头服务器上!发布时也会发生这种情况(mergeReleaseResources 除外)。我尝试了 运行 --info--debug 但它没有给我任何有用的东西。我还尝试过使用 Oracle 的 JDK 而不是 OpenJDK 并在机器构建上安装本地 X 服务器,但这也没有改变任何东西。这是在 repo 的新克隆副本上,尽管我认为该错误不是 microG 特有的。

这是我的结果 运行 ./gradlew build --stacktrace: https://gist.github.com/milkey-mouse/cb6b75b5116cf369603dec46e214e914

您可以尝试将 -Djava.awt.headless=true 添加到 gradle.properties 文件中的 jvmargs

org.gradle.jvmargs=-Djava.awt.headless=true

另请看示例here

这是similar question,但与Gradle无关。