8

I am using newest Mac OS X and I am creating a GUI element inside a Gradle file. I am currently using jdk1.7.0_55 and I have imported groovy.swing.SwingBuilder, when I run the project I am getting the following error:

java.awt.AWTError: "Toolkit not found: apple.awt.CToolkit

I have tried running the script as a headless server using System.setProperty('java.awt.headless', 'true')

I would like to have a solution that I can include directly in the Gradle project file, instead of trying to figure out what is in my accesibilities.properties file (that may not exist on a particular system, like it does not on my system).

Also the project must use an internal solution, external libraries are not allowed.

Would really appreciate any help on this matter.

Edited: Sample Code

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();
                    })
                }
            }
        }
    }
}
Rao
  • 20,781
  • 11
  • 57
  • 77
ahmad
  • 2,149
  • 4
  • 21
  • 38

2 Answers2

0

I've faced same issue with Android Studio 0.8.6 and solved it with custom gradle installation. Just downloaded gradle 1.12 and set path to it in preferences.

Renatus
  • 1,123
  • 13
  • 20
  • 1
    Still get the same `java.awt.AWTError: "Toolkit not found: apple.awt.CToolkit` error... – Sakiboy Sep 27 '14 at 16:45
  • Tried your solution and failed. It's sad no one has been able to help on this issue, would appreciate any help anyone can provide. – ahmad Nov 03 '14 at 15:21
0

The question is a few years old, but with the following gradle build file (which is essentially the same as the OPs):

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();
              })
            }
          }
      }
  }
}

executing:

~> gradle doit

results in the following screen:

enter image description here

in other words, at least with this version of gradle, operating system, java etc this seems to work.

Matias Bjarland
  • 4,124
  • 1
  • 13
  • 21