Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to create component for 'dialog' reason: java.awt.HeadlessException

After updating gradle to version 3.0.0-beta3 I have this error when I try to display a dialog box to ask for the password of the key.

I tried to add System.setProperty('java.awt.headless', 'false') but it did not work and I found nothing very new on google ....

Error:(20, 1) Failed to create component for 'dialog' reason: java.awt.HeadlessException

java.awt.HeadlessException (no error message)

import groovy.swing.SwingBuilder

gradle.taskGraph.whenReady { taskGraph ->
        def storePassword = ''
        def keyPassword = ''
        if (System.console() == null) {
            new SwingBuilder().edt {
                dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) {
                    vbox {
                        label(text: "Please enter store passphrase:")
                        def input1 = passwordField()
                        label(text: "Please enter key passphrase:")
                        def input2 = passwordField()
                        button(defaultButton: true, text: 'OK', actionPerformed: {
                            storePassword = input1.password;
                            keyPassword = input2.password;
                            dispose();
                        })
                    }
                }
            }
        } else {
            storePassword = System.console().readPassword("\nPlease enter store passphrase: ")
            keyPassword = System.console().readPassword("\nPlease enter key passphrase: ")
        }

        if (storePassword.size() <= 0 || keyPassword.size() <= 0) {
            throw new InvalidUserDataException("You must enter the passwords to proceed.")
        }

        storePassword = new String(storePassword)
        keyPassword = new String(keyPassword)

        android.signingConfigs.Keys.storePassword = storePassword
        android.signingConfigs.Keys.keyPassword = keyPassword
}
like image 522
filol Avatar asked Aug 27 '17 20:08

filol


1 Answers

For me it finally worked when I added System.setProperty('java.awt.headless', 'false') twice:

  • immediately after import
  • after System.console() == null check

But then it happens be ok with only after System.console() == null check.

Don't forget to ./gradlew --stop as mentioned before.

like image 101
ilya Avatar answered Oct 15 '22 02:10

ilya