Failed to create component for 'dialog' reason: java.awt.HeadlessException

To solve this problem you have to add these 3 line exactly in this order (other orders don't work)

apply plugin: 'com.android.application'

import groovy.swing.SwingBuilder

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

def doPromptForPassword(msg) {
if (System.console() == null) {
    System.setProperty('java.awt.headless', 'false') // worked for me
    def ret = null
    new SwingBuilder().edt {
        dialog(modal: true, title: 'Enter password', alwaysOnTop: t

Just add System.setProperty('java.awt.headless', 'false') before import groovy.swing.SwingBuilder and kill gradle deamon with ./gradlew --stop

it give you something liket that :

apply plugin: 'com.android.application'

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

import groovy.swing.SwingBuilder