我正在使用最新的 Mac OS X,我正在 Gradle 文件中创建一个 GUI 元素。我目前使用的是 jdk1.7.0_55 并且我已经导入了 groovy.swing.SwingBuilder
,当我运行项目时,我收到以下错误:
java.awt.AWTError: "Toolkit not found: apple.awt.CToolkit
我尝试使用
System.setProperty('java.awt.headless', 'true')
将脚本作为 headless 服务器运行我想要一个可以直接包含在 Gradle 项目文件中的解决方案,而不是试图找出我的
accesibilities.properties
中的内容。文件(在特定系统上可能不存在,就像在我的系统上不存在一样)。此外,项目必须使用内部解决方案,不允许使用外部库。
真的很感激在这个问题上的任何帮助。
编辑:示例代码
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(':CustomApp:assembleRelease')) {
def pass = ''
if(System.console() == null) {
new SwingBuilder().edt { // Error occurs here.
dialog(modal: true,
alwaysOnTop: true,
resizable: false,
locationRelativeTo: null,
pack: true,
show: true
)
{
vbox {
label(text: "Enter password:")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = input.password;
dispose();
})
}
}
}
}
}
最佳答案
我在 Android Studio 0.8.6 上遇到了同样的问题,并通过自定义 gradle 安装解决了这个问题。
刚刚下载了 gradle 1.12 并在首选项中设置了它的路径。
关于macos - Groovy SwingBuilder() apple.awt.CToolkit 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24618710/