android – 无法为’dialog’原因创建组件:java.awt.HeadlessException

前端之家收集整理的这篇文章主要介绍了android – 无法为’dialog’原因创建组件:java.awt.HeadlessException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
将gradle更新到版本3.0.0-beta3后,当我尝试显示一个对话框以询问密钥的密码时出现此错误.

我试图添加System.setProperty(‘java.awt.headless’,’false’),但它没有用,我发现谷歌上没有什么新东西….

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
}

解决方法

只需在导入groovy.swing.SwingBuilder之前添加System.setProperty(‘java.awt.headless’,’false’)并使用./gradlew -stop杀死gradle deamon

它给你的东西:

apply plugin: 'com.android.application'

System.setProperty('java.awt.headless','false')

import groovy.swing.SwingBuilder

猜你在找的Android相关文章