Issue
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
}
Solution
Just add System.setProperty('java.awt.headless', 'false')
before import groovy.swing.SwingBuilder
and kill gradle deamon with ./gradlew --stop
it give you something liket that :
apply plugin: 'com.android.application'
System.setProperty('java.awt.headless', 'false')
import groovy.swing.SwingBuilder
Answered By - filol
Answer Checked By - Pedro (JavaFixing Volunteer)