Ionic cordova run android FAILURE

Hi, when I try to start my Ionic App with the
ionic cordova run android
or the
ionic cordova emulate android
the process fails :frowning:

I’ve this output in Console:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
aapt2 is missing on 'C:\Users\f.menghini\AppData\Local\Android\sdk\build-tools
\27.0.3\aapt2.exe'

* 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
21 actionable tasks: 1 executed, 20 up-to-date
(node:7156) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
aapt2 is missing on 'C:\Users\f.menghini\AppData\Local\Android\sdk\build-tools
\27.0.3\aapt2.exe'

* 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
(node:7156) DeprecationWarning: Unhandled promise rejections are deprecated. In
the future, promise rejections that are not handled will terminate the Node.js p
rocess with a non-zero exit code.

[OK] Your app has been deployed.
     Did you know you can live-reload changes from your app with --livereload?

I’ve checked in the specified path and the aapt2.exe doesn’t exist.

How can I resolve this trouble?

Nobody can help me?
:frowning: :frowning: :frowning:

What is your ionic info output?

1 Like

ionic info:

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

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

global packages:

    cordova (Cordova CLI) : 8.0.0
 

local packages:

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

System:

    Node : v7.9.0
    npm  : 4.2.0 
    OS   : Windows 7

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro
1 Like

Remove all the icon and splash image inside the ./resources/android (broken image may be). Then generate again by running ionic cordova resources and build it again. Run your command ionic cordova run android afterward.

1 Like

I’ve removed the images as you told me, I’ve generate images again, then I’ve tried to rebuild project with
ionic cordova build
but I’ve the same error :frowning:

Did you install Android? Try to install Android Studio, open a new Project with it and open the SDK Manager from the toolbar (should be 2nd symbol from right) and install Android 8, Android SDK Build Tools, Android SDK Platform-Tools, Android SDK Tools and Support Repository. Also add the Android SDK Location you find in the SDK Manager to your Path variable:

set ANDROID_HOME=C:\<installation location>\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

1 Like

I’ve installed Android Studio and the reccomended packages yet, but now I’ll try to uninstall and reinstall them as you have told me.
I’ll let you know as soon as the operation is over :slight_smile:

Now the Android SDK Location is added, in ionic info I have:

ANDROID_HOME : C:\Users…\Android\Sdk

and it’s the right directory!

But the output of ionic cordova run android is:

...
cordova run android
Android Studio project detected

[11:49:28]  lint finished in 5.03 s
ANDROID_HOME=C:\Users\f.menghini\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_151
studio
Subproject Path: CordovaLib
Subproject Path: app
(node:6828) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): Error: cmd: Command failed with exit code ENOENT
(node:6828) DeprecationWarning: Unhandled promise rejections are deprecated. In
the future, promise rejections that are not handled will terminate the Node.js p
rocess with a non-zero exit code.

[OK] Your app has been deployed.
     Did you know you can live-reload changes from your app with --livereload?

I don’t understand this trouble :sob::sob::sob:

Is it working with ionic serve or do you get the same error?

It seems like many people are getting this error.

1 Like

Wow! Okay, lets try something else. The project path, if the project path is long, try to change the project location to a direct/short path

For example:
Old path: c:\users\your-user-name\projects-container\folders\project-folder
New path: c:\users\your-user-name\project-folder

If I could remember, I once had a similar issue though mine was as a result of changing my project folder name from upper case to lower case (PRojects -> projects).

ionic serve

Is working correctly, It launch my Browser and run the app :disappointed_relieved:

I get
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon (subsequent builds will be faster)

What do you get with gradle -v ?

You may have to install gradle correctly.

1 Like

I’ve tried to change the Project location to a shorter one but it doesn’t work.
I’ve also tried to change name of the Project folder with a new name without any uppercase char, but it doesn’t work.

Gradle doesn’t exist, gradle isnt’ a recognized command from my prompt.

I’ve installed the latest gradle (4.4.1) with Chocolatey.

Now I’ve the same output when I’m trying to run the app:

...
cordova run android
Android Studio project detected

[12:27:55]  lint finished in 6.93 s
ANDROID_HOME=C:\Users\f.menghini\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_151
studio
Subproject Path: CordovaLib
Subproject Path: app
(node:1680) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code ENOENT
(node:1680) DeprecationWarning: Unhandled promise rejections are deprecated. In
the future, promise rejections that are not handled will terminate the Node.js p
rocess with a non-zero exit code.

[OK] Your app has been deployed.
     Did you know you can live-reload changes from your app with --livereload?

I would recommend two options.

First check, if gradle -v now works. You may have to add the path:

In File Explorer right-click on the This PC (or Computer) icon,
then click Properties → Advanced System Settings → Environmental Variables.

Under System Variables select Path, then click Edit.
Add an entry for C:\<gradle-path>\bin . Click OK to save.

or use set PATH=%PATH%;C:\<gradle-path>\bin and check with echo %path%

Another option is to reinstall android platform for your project by using ionic cordova platform remove android and ionic cordova platform add android

1 Like

Now gradle -v works and the output is:

------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------

Build time:   2017-12-20 15:45:23 UTC
Revision:     10ed9dc355dc39f6307cc98fbd8cea314bdd381c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_151 (Oracle Corporation 25.151-b12)
OS:           Windows 7 6.1 amd64

But when I’m trying to remove android platform I’ve this error:

(node:5988) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): Error: cmd: Command failed with exit code ENOENT
(node:5988) DeprecationWarning: Unhandled promise rejections are deprecated. In
the future, promise rejections that are not handled will terminate the Node.js p
rocess with a non-zero exit code.

:face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth:

I think it is enough to delete the android folder from platforms in your project by hand.

You could also try to reinstall nodejs. If you get that error in many commands, it may be a problem with node, cordova or the ionic cli

1 Like

I’ve done it, manually remove folder, remove and install nodejs, but the error persists :frowning:
I can’t add android platform now, so far this command has never given me any kind of problem :confused:

Can you test it with a new ionic project? If it occurs there, too, we know that its a problem with the tools.

1 Like