Getting error while doing 'cordova build android --release'


#1

I am getting a weird error for the build command in android.

error says

What went wrong:
Failed to create component for 'dialog' reason: java.awt.HeadlessException
> java.awt.HeadlessException (no error message)

cordova.gradle

def doPromptForPassword(msg) {
    if (System.console() == null) {
        def ret = null
        new SwingBuilder().edt {
            dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) {
                vbox {
                    label(text: msg)
                    def input = passwordField()
                    button(defaultButton: true, text: 'OK', actionPerformed: {
                        ret = input.password;
                        dispose();
                    })
                }
            }
        }
        if (!ret) {
            throw new GradleException('User canceled build')
        }
        return new String(ret)
    } else {
        return System.console().readPassword('\n' + msg);
    }
}

What I am doing wrong? It was working fine in previous build


#2

What is your ionic info output?
What is this cordova.gradle for?


#3

This is my ionic info

cli packages: (/Users/RavikumarShah/Desktop/TruckStop/NewFolder/TruckstopMobile/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0 

local packages:

    @ionic/app-scripts : 3.0.0
    Cordova Platforms  : android 6.4.0 ios 4.5.4
    Ionic Framework    : ionic-angular 3.7.1-201710241735

System:

    Android SDK Tools : 26.0.2
    ios-deploy        : 1.9.2 
    ios-sim           : 5.0.13 
    Node              : v6.11.3
    npm               : 2.15.12 
    OS                : macOS High Sierra
    Xcode             : Xcode 9.1 Build version 9B55 

Environment Variables:

    ANDROID_HOME : /usr/local/opt/android-sdk

Misc:

    backend : legacy

This is a Cordova.gradle file to build android production version.
THe dialog is to enter signing APK key


#4

This is not necessary, cordova-android prompts by itself when no password is supplied when building.

Can you build when you supply the password?


#5

ahh, I am not sure, but How can I pass password with this command?


#6

See the docs: https://cordova.apache.org/docs/en/7.x/guide/platforms/android/index.html#signing-an-app


#7

I don’t understand why people don’t just answer the question.

The tools do this, not the user.

I have now wasted the better part of 24 hours with the same error. I have removed gradle, android, cordova, all my platforms, plugins, node modules, reinstalled, a dozen times, to no avail - even if I go way back to Gradle 2.1, I get the same error, and I didn’t even yesterday morning.

Does anyone know where this error actually comes from, and how to actually fix it, beyond just saying “don’t do what Cordova actually does for you”?

@imrvshah were you able to eventually solve it?


#8

For anyone who comes across this, this seems to have something to do with Android SDK 26. It flat out does not allow showing of dialogs during CLI builds; the only solution is to add your key passwords to the command line, or build with Android Studio where you can either enter the keys or get prompted for them.


#9

this worked for me:
1- Put your nameapp_key.keystore file at the root project ionicprojects/nameapp/nameapp_key.keystore

2-Edit your build.grade file at /platform/android/app/build.gradle
Line 229:
if (cdvReleaseSigningPropertiesFile) {
signingConfigs {
release {
// like this…
keyAlias="nameapp-key"
keyPassword="your password combination"
storeFile=null
storePassword=“your password combination”
}

3.-Go to the project folder and type this in your terminal:
cordova build android --release – --keystore=“nameapp_key.keystore” --alias=nameapp-key

4-that’s it, your apk will be here nameappfolder/platforms/android/app/build/outputs/apk/release/app-release.apk

I hope it works for you

my ionic info:
cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.1
ionic (Ionic CLI) : 3.19.1

System:

Node : v6.9.1
npm  : 5.6.0 
OS   : macOS High Sierra

Misc:

backend : legacy

#10

It works for me… thanks a lot.

$ ionic info

cli packages: (C:\Users\user\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.1
ionic (Ionic CLI) : 3.19.1

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.5
Cordova Platforms  : android 6.4.0 ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 25.2.5
Node              : v8.9.3
npm               : 5.5.1
OS                : Windows 10

Environment Variables:

ANDROID_HOME : C:\Program Files (x86)\Android\android-sdk

Misc:

backend : pro

#11

i am getting error for android build tool

Microsoft Windows [Version 10.0.16299.192]
© 2017 Microsoft Corporation. All rights reserved.

C:\Users\Owner>cd desktop\test\myapp

C:\Users\Owner\Desktop\test\myapp>ionic cordova build android
Running app-scripts build: --platform android --target cordova
[19:13:21] build dev started …
[19:13:21] clean started …
[19:13:21] clean finished in 32 ms
[19:13:21] copy started …
[19:13:23] deeplinks started …
[19:13:23] deeplinks finished in 500 ms
[19:13:23] transpile started …
[19:13:31] transpile finished in 8.07 s
[19:13:31] preprocess started …
[19:13:31] preprocess finished in 18 ms
[19:13:31] webpack started …
[19:13:32] copy finished in 10.51 s
[19:13:41] webpack finished in 10.27 s
[19:13:41] sass started …
Without from option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to undefined to prevent this warning.
[19:13:47] sass finished in 5.31 s
[19:13:47] postprocess started …
[19:13:47] postprocess finished in 16 ms
[19:13:47] lint started …
[19:13:47] build dev finished in 25.94 s

cordova build android
Android Studio project detected

ANDROID_HOME=C:\SocketeQ\windowsandroid_root\system\bin\platform-tools
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
studio
Subproject Path: CordovaLib
Subproject Path: app
[19:13:54] lint finished in 7.08 s

FAILURE: Build failed with an exception.

  • Where:
    Script ‘C:\Users\Owner\Desktop\test\myapp\platforms\android\CordovaLib\cordova.gradle’ line: 68

  • What went wrong:
    A problem occurred evaluating project ‘:CordovaLib’.

No installed build tools found. Install the Android build tools version 19.1.0 or higher.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • Where:
    Script ‘C:\Users\Owner\Desktop\test\myapp\platforms\android\CordovaLib\cordova.gradle’ line: 68

  • What went wrong:
    A problem occurred evaluating project ‘:CordovaLib’.

No installed build tools found. Install the Android build tools version 19.1.0 or higher.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s

[ERROR] An error occurred while running cordova build android (exit code 1).

IONIC INFO

cli packages: (C:\Users\Owner\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.1
ionic (Ionic CLI) : 3.19.1

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 7.0.0 ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v8.9.4
npm  : 5.6.0
OS   : Windows 10

Environment Variables:

ANDROID_HOME : C:\Users\Owner\AppData\Local\Android\Sdk\platform-tools

Misc:

backend : pro

how can i solve this issue plz help


#12

I have no experience about cordova-android 7.0.0. Maybe, you can try downgrade to 6.4.0 and verify whether joelss7’s method can work. It maybe help you find the issue.

for issuse:
No installed build tools found. Install the Android build tools version 19.1.0 or higher.

suggest you to check your SDK manager wether install related build tools.


#13

I solved with inline password:
$ ionic cordova build android --release -- -- --keystore=my.keystore --storePassword=XXX --password=XXX --alias=myAlias