MilkeyMouse MilkeyMouse - 3 years ago 134
Android Question

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

I always get this error when I try to build 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


This is on a headless server that doesn't even have an X server installed! This happens for release (except with
mergeReleaseResources
) as well. I tried running with
--info
and
--debug
but it didn't give me anything useful. I've also tried switching to use Oracle's JDK instead of OpenJDK and installing a local X server on the machine building but that didn't change anything either. This is on a freshly cloned copy of the repo, although I don't think the error is specific to microG.

Here are my results running
./gradlew build --stacktrace
: https://gist.github.com/milkey-mouse/cb6b75b5116cf369603dec46e214e914

Answer Source

You can try adding -Djava.awt.headless=true to your jvmargs in gradle.properties file. Please take a look at example here.

Here is the similar question, but not related to Gradle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download