将gradle更新到版本3.0.0-beta3后,尝试显示对话框以请求密钥密码时,我遇到了此错误。
我尝试添加System.setProperty('java.awt.headless', 'false')
但它没有起作用,并且在谷歌上没有找到任何很新的东西....
错误:(20,1)无法为'dialog'创建组件原因:java.awt.HeadlessException
java.awt.HeadlessException(没有错误消息)
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
}