Cordova build android takes more than 10 minutes


#1

Hey! After upgrading to ionic 3 cli it takes a lot of time (OMG, sometimes 11-12 minutes) to build the .apk. I’ve tried to build new app from super Ionic template and it takes more than 7 minutes (better but still not OK). No errors, works well, just loooong! No found same reports from other users on forums. Have you any idea what I do wrong? Build for iOS works as usual.
My system:
Mac mini with 8GB RAM,
package.json (from super template)

{
    "name": "testBuild",
    "version": "0.0.1",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@ionic-native/camera": "3.12.1",
        "@ionic-native/core": "3.12.1",
        "@ionic-native/google-maps": "3.12.1",
        "@ionic-native/splash-screen": "3.12.1",
        "@ionic-native/status-bar": "3.12.1",
        "@ionic/storage": "2.0.1",
        "@ngx-translate/core": "6.0.1",
        "@ngx-translate/http-loader": "0.0.3",
        "cordova-android": "^6.2.3",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.2",
        "cordova-plugin-whitelist": "^1.3.1",
        "ionic-angular": "3.5.0",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "5.4.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
    },
    "devDependencies": {
        "@ionic/app-scripts": "1.3.12",
        "@ionic/cli-plugin-cordova": "1.4.0",
        "@ionic/cli-plugin-ionic-angular": "1.3.1",
        "typescript": "2.3.4"
    },
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {}
        },
        "platforms": [
            "android"
        ]
    }
}

Ionic info:

global packages:

    @ionic/cli-plugin-proxy : 1.3.1
    @ionic/cli-utils        : 1.4.0
    Cordova CLI             : 7.0.1 
    Ionic CLI               : 3.4.0

local packages:

    @ionic/app-scripts              : 1.3.12
    @ionic/cli-plugin-cordova       : 1.4.0
    @ionic/cli-plugin-ionic-angular : 1.3.1
    Cordova Platforms               : android 6.2.3
    Ionic Framework                 : ionic-angular 3.5.0

System:

    Node       : v7.10.0
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.2 Build version 8E2002 
    ios-deploy : 1.9.1 
    ios-sim    : 5.0.13 
    npm        : 4.2.0 

There is full output here:

ionic cordova build android
Running app-scripts build: --iscordovaserve --externalIpRequired --nobrowser

[15:02:47]  build dev started ... 
[15:02:47]  clean started ... 
[15:02:47]  clean finished in 77 ms 
[15:02:47]  copy started ... 
[15:02:47]  transpile started ... 
[15:02:55]  transpile finished in 8.15 s 
[15:02:55]  preprocess started ... 
[15:02:55]  deeplinks started ... 
[15:02:55]  deeplinks finished in 64 ms 
[15:02:55]  preprocess finished in 119 ms 
[15:02:55]  webpack started ... 
[15:02:58]  copy finished in 11.05 s 
[15:03:10]  webpack finished in 14.42 s 
[15:03:10]  sass started ... 
[15:03:13]  sass finished in 3.21 s 
[15:03:13]  postprocess started ... 
[15:03:13]  postprocess finished in 52 ms 
[15:03:13]  lint started ... 
[15:03:13]  build dev finished in 26.34 s 
> cordova build android
⠦ Running command [15:04:06]  tslint: src/models/item.ts, line: 12 
            Property 'fields' is declared but never used. 

      L12:    constructor(private fields: any) {
      L13:      // Quick and dirty extend/assign fields to this model

[15:04:06]  tslint: src/pages/map/map.ts, line: 6 
            'google' is declared but never used. 

       L6:  declare var google: any;

[15:04:06]  lint finished in 53.13 s 
✔ Running command - done! -   <-----  IT HANGS HERE!!!
ANDROID_HOME=/Users/---/Downloads/
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
	at build_bdz8blnter5mvx0xolt0n4cna.run(/Users/---/ Downloads/projects/testBuild/platforms/android/build.gradle:137)
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:preBuild UP-TO-DATE
:preDebugBuild UP-TO-DATE
:checkDebugManifest
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl UP-TO-DATE
:CordovaLib:compileDebugNdk UP-TO-DATE
:CordovaLib:compileLint UP-TO-DATE
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugShaders UP-TO-DATE
:CordovaLib:compileDebugShaders UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles UP-TO-DATE
:CordovaLib:packageDebugRenderscript UP-TO-DATE
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:processDebugResources UP-TO-DATE
:CordovaLib:generateDebugSources UP-TO-DATE
:CordovaLib:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
:CordovaLib:processDebugJavaRes UP-TO-DATE
:CordovaLib:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:CordovaLib:transformClassesAndResourcesWithSyncLibJarsForDebug UP-TO-DATE
:CordovaLib:mergeDebugJniLibFolders UP-TO-DATE
:CordovaLib:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:CordovaLib:transformNative_libsWithSyncJniLibsForDebug UP-TO-DATE
:CordovaLib:bundleDebug UP-TO-DATE
:prepareOrgApacheCordovaCordovaLib623DebugLibrary UP-TO-DATE
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileDebugRenderscript UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:mergeDebugResources UP-TO-DATE
:processDebugManifest UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:compileDebugJavaWithJavac UP-TO-DATE
:compileDebugNdk UP-TO-DATE
:compileDebugSources UP-TO-DATE
:mergeDebugShaders UP-TO-DATE
:compileDebugShaders UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:transformClassesWithDexForDebug UP-TO-DATE
:mergeDebugJniLibFolders UP-TO-DATE
:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:processDebugJavaRes UP-TO-DATE
:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:validateSigningDebug
:packageDebug UP-TO-DATE
:assembleDebug UP-TO-DATE
:cdvBuildDebug UP-TO-DATE

BUILD SUCCESSFUL

Total time: 15 mins 31.677 secs
Built the following apk(s): 
	/Users/---/Downloads/projects/testBuild/platforms/android/build/outputs/apk/android-debug.apk

Add a native plugin, and 'build android' lasted longer than 20 minutes
#2

Could you please post the complete output of your build process?
This just shows that lint was ok fast - not what is taking too long.


#3

Yes, i have updated my post. Now it took 15 min! god


#4

This is still not the full output. Please copy everything, including the command you executed and the complete following output. Not parts, not missing something, really everything from the moment you executed the command until you got your command line back to execute the next command.


#5

Yeah we’ve got the same issue
it seems to be a problem with ionic-app-scripts

Try changing from 1.3.12 to 1.3.7, that “fixed” it for me.


#6

i don’t believe it’s issue with app-scripts. At current commercial project I use 1.3.7, and i downgraded starter project to 1.3.7. No changes


#7

Looking at the now posted complete output, it doesn’t look to be Ionic at all. The problem is more in the build command of Cordova, that Ionic triggers. But let’s test some more:

Could you fix these to make sure this isn’t causing anything strange and post the output again please?

Please also run cordova build android directly and show us the complete output. Does this also take that long?


#8

still a lot of time, output almost the same but now it hangs on

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
	at build_bdz8blnter5mvx0xolt0n4cna.run(/Users/---/Downloads/projects/testBuild/platforms/android/build.gradle:137)
cordova build android
ANDROID_HOME=/Users/---/Downloads/
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
	at build_bdz8blnter5mvx0xolt0n4cna.run(/Users/---/Downloads/projects/testBuild/platforms/android/build.gradle:137)
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:preBuild UP-TO-DATE
:preDebugBuild UP-TO-DATE
:checkDebugManifest
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl UP-TO-DATE
:CordovaLib:compileDebugNdk UP-TO-DATE
:CordovaLib:compileLint UP-TO-DATE
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugShaders UP-TO-DATE
:CordovaLib:compileDebugShaders UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles UP-TO-DATE
:CordovaLib:packageDebugRenderscript UP-TO-DATE
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:processDebugResources UP-TO-DATE
:CordovaLib:generateDebugSources UP-TO-DATE
:CordovaLib:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
:CordovaLib:processDebugJavaRes UP-TO-DATE
:CordovaLib:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:CordovaLib:transformClassesAndResourcesWithSyncLibJarsForDebug UP-TO-DATE
:CordovaLib:mergeDebugJniLibFolders UP-TO-DATE
:CordovaLib:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:CordovaLib:transformNative_libsWithSyncJniLibsForDebug UP-TO-DATE
:CordovaLib:bundleDebug UP-TO-DATE
:prepareOrgApacheCordovaCordovaLib623DebugLibrary UP-TO-DATE
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileDebugRenderscript UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:mergeDebugResources UP-TO-DATE
:processDebugManifest UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:compileDebugJavaWithJavac UP-TO-DATE
:compileDebugNdk UP-TO-DATE
:compileDebugSources UP-TO-DATE
:mergeDebugShaders UP-TO-DATE
:compileDebugShaders UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:transformClassesWithDexForDebug UP-TO-DATE
:mergeDebugJniLibFolders UP-TO-DATE
:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:processDebugJavaRes UP-TO-DATE
:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:validateSigningDebug
:packageDebug UP-TO-DATE
:assembleDebug UP-TO-DATE
:cdvBuildDebug UP-TO-DATE

BUILD SUCCESSFUL

Total time: 6 mins 43.874 secs
Built the following apk(s): 
	/Users/---/Downloads/projects/testBuild/platforms/android/build/outputs/apk/android-debug.apk

#9

Yeah, the console output isn’t really 100% exact to what is taking so long - that is why the Ionic part that happens before explicitly outputs duration.

But as you can see, this has nothing to do with Ionic itself, but is a pure Cordova issue. Your upgrade to Ionic CLI 3.x couldn’t cause this, maybe you upgraded the Cordova CLI and Cordova Android platform at the same time?

Have you tried removing and re-adding the android platform already?
Is there anything running that could cause files being written in /platforms to hang? (anti virus or anything)
What does cordova requirements output?


#10

I upgraded gradle from 3.5 to 4.0, tried rm/add platform, downgraded cordova from 7 to 6.5, restarted mac - no results( now i believe it’s not ionic issue. I have no antivirus, firewall is off

cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-19,android-23,android-25,Google Inc.:Google APIs:19,Google Inc.:Google APIs:23
Gradle: installed 

Requirements check results for ios:
Apple OS X: installed darwin
Xcode: installed 8.3.2
ios-deploy: installed 1.9.1
CocoaPods: installed

#11

Then I would do the following:

  1. Run cordova build android --debug or cordova build android --verbose (one of both will give you more output hopefully that is useful)
  2. try another machine if available to see the same problem exists there
  3. try to create a new minimal project with ionic start blank blank and see if this also takes so long

#12

Thanks. I have already tried 1 and 3. So changing machine - my last chance :wink:


#13

What did #1 output?
And #3 took the same amount of time to build?


#14

you can delete this topic. It was such a stupid thing. Just moved android sdk related files to another separate folder and voila - ionic cordova builds in 26 secs. Previously it worked ok, don’t know what happened. Sorry guys!!!


#15

Interesting!

Could you elaborate what files you moved where exactly?

(We don’t really delete stuff here but mark a good description of the resolution as… resolution so the topic gets a green checkmark and is visually “solved” :slight_smile: )


#16

So initially my android-sdk folders like build-tools, platform-tools etc. were at Downloads folder. Shame for me, it is a bad practice. Bit by bit the Downloads folder became fully of files, I believe it was the reason why java sdk stuff worked so slow. Now all sdk-related folders are in Downloads/android_sdk. Hope in future this topic will help someone not to spend whole work day for such a stupid thing :slight_smile:


#17

It’s kinda related to your explaination, in my case I deleted the SDK folder and reinstall all with Android Studio. And now it tooks less than a minute.
By the way, thanks :slight_smile:


#18

I’m still struggling with this issue and it’s very sporadic. Not sure what is causing it. I can run ionic cordova run android -l -c and it’s fine one time and then again and I’m stuck on Built the following apk(s)… for 10 - 20 minutes. If anyone has any other solutions let me know. I’ve tried cordova clean android as well removing and adding the android platform.


#19

Use SSD instead of HDD, increase your PC memory, and use latest Gradle version with gradle.properties.

example:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8