8

我正在使用最新的 Mac OS X,并且正在 Gradle 文件中创建一个 GUI 元素。我目前正在使用 jdk1.7.0_55 并且我已经导入groovy.swing.SwingBuilder,当我运行项目时,我收到以下错误:

java.awt.AWTError:“找不到工具包:apple.awt.CToolkit

我尝试将脚本作为无头服务器运行,使用System.setProperty('java.awt.headless', 'true')

我想要一个可以直接包含在 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();
                    })
                }
            }
        }
    }
}
4

2 回答 2

0

我在使用 Android Studio 0.8.6 时遇到了同样的问题,并通过自定义 gradle 安装解决了这个问题。刚刚下载了 gradle 1.12 并在首选项中设置了它的路径。

于 2014-09-22T11:48:52.110 回答
0

这个问题是几年前的问题,但是使用以下 gradle 构建文件(本质上与 OP 相同):

import groovy.swing.SwingBuilder

task doit {}

gradle.taskGraph.whenReady { taskGraph ->
  if(taskGraph.hasTask(doit)) {
      def pass = ''
      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();
              })
            }
          }
      }
  }
}

执行:

~> gradle doit

结果出现以下屏幕:

在此处输入图像描述

换句话说,至少对于这个版本的 gradle、操作系统、java 等,这似乎是可行的。

于 2018-05-17T06:34:03.643 回答