Ionic cordova build error

Hello,

i have this error when i run the command ionic cordova build since i want to get the apk of my ionic application.

it gives me this output:

C:\Users\User\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master (2)\scanbot-sdk-example-ionic2-master>ionic cordova build
? What platform would you like to build: ios, android: android
Running app-scripts build: --iscordovaserve --externalIpRequired --nobrowser

[23:38:06]  build dev started ...
[23:38:06]  clean started ...
[23:38:06]  clean finished in less than 1 ms
[23:38:06]  copy started ...
[23:38:06]  transpile started ...
[23:38:10]  transpile finished in 4.43 s
[23:38:10]  preprocess started ...
[23:38:10]  preprocess finished in 16 ms
[23:38:10]  webpack started ...
[23:38:11]  copy finished in 4.70 s
[23:38:20]  webpack finished in 9.54 s
[23:38:20]  sass started ...
[23:38:21]  sass finished in 1.05 s
[23:38:21]  postprocess started ...
[23:38:21]  postprocess finished in less than 1 ms
[23:38:21]  lint started ...
[23:38:21]  build dev finished in 15.28 s
> cordova build android
\ Running command [23:38:39]  lint finished in 18.39 s
âś– Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

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

        Error: Failed to find 'ANDROID_HOME' environment variable. Try setting
        setting it manually.
        Failed to find 'android' command in your 'PATH'. Try update your 'PATH'
        to include path to valid SDK directory.

What is the error all about and how can i solve it.

Thank you :slight_smile:

It seems as though you are missing the android SDK which is required to build for android.

The simplest solution is to just install android studio and that will solve the issue by installing the SDK.

https://developer.android.com/studio/index.html

For more information see: https://ionicframework.com/docs/intro/deploying/

Good, i will try your solution and i will come back with the result :slight_smile:

I am back,

i try your solution which is installing the latest version of ''Android Studio" that comes with the Android SDK.

and then i try again to generate the apk for the ionic application and the console returns me this error:

C:\Users\User\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master (2)\scanbot-sdk-example-ionic2-master>ionic cordova build
? What platform would you like to build: ios, android: android
Running app-scripts build: --iscordovaserve --externalIpRequired --nobrowser

[04:15:28]  build dev started ...
[04:15:28]  clean started ...
[04:15:28]  clean finished in 196 ms
[04:15:28]  copy started ...
[04:15:28]  transpile started ...
[04:15:50]  transpile finished in 21.68 s
[04:15:50]  preprocess started ...
[04:15:50]  preprocess finished in less than 1 ms
[04:15:50]  webpack started ...
[04:15:53]  copy finished in 25.00 s
[04:16:10]  webpack finished in 20.14 s
[04:16:10]  sass started ...
[04:16:22]  sass finished in 11.75 s
[04:16:22]  postprocess started ...
[04:16:22]  postprocess finished in less than 1 ms
[04:16:22]  lint started ...
[04:16:22]  build dev finished in 53.92 s
> cordova build android
\ Running command [04:16:28]  lint finished in 6.71 s
âś– Running command - failed!

[ERROR] Cordova encountered an error.
       You may get more insight by running the Cordova command above directly.

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

       ANDROID_HOME=C:\Users\User\AppData\Local\Android\sdk
       JAVA_HOME=C:\Program Files\java\jdk1.7.0_67
       Error: Requirements check failed for JDK 1.8 or greater

What should i do to solve the problem !!:expressionless:

and thanks for your help :slight_smile:

It is requiring JDK 1.8 which you can find and download here http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

i download it, but also output me some error:

this is the error:

> cordova build android
\ Running command [20:44:24]  lint finished in 5.49 s
âś– Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

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

        ANDROID_HOME=C:\Users\User\AppData\Local\Android\sdk
        JAVA_HOME=C:\Program Files\java\jdk1.8.0_131
        Subproject Path: CordovaLib
        Download https://jcenter.bintray.com/com/android/tools/lint/lint-checks/25.2.3/lint-checks-25.2.3.jar
        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_35yvq9nqv5571mebe4jm6vlr6.run(C:\Users\User\Desktop\ionic
        2\44\scanbot-sdk-example-ionic2-master (2)\scanbot-sdk-example-ionic2-master\platforms\android\build.gradle:138)
        Checking the license for package Android SDK Platform 25 in C:\Users\User\AppData\Local\Android\sdk\licenses
        Warning: License for package Android SDK Platform 25 not accepted.

        FAILURE: Build failed with an exception.

        * What went wrong:
        A problem occurred configuring root project 'android'.
        > You have not accepted the license agreements of the following SDK components:
        [Android SDK Platform 25].
        Before building your project, you need to accept the license agreements and complete the installation of the
        missing components using the Android Studio SDK Manager.
        Alternatively, to learn how to transfer the license agreements from one workstation to another, go to
        http://d.android.com/r/studio-ui/export-licenses.html

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

        Total time: 3 mins 49.444 secs
        Error: cmd: Command failed with exit code 1 Error output:
        FAILURE: Build failed with an exception.

        * What went wrong:
        A problem occurred configuring root project 'android'.
        > You have not accepted the license agreements of the following SDK components:
        [Android SDK Platform 25].
        Before building your project, you need to accept the license agreements and complete the installation of the
        missing components using the Android Studio SDK Manager.
        Alternatively, to learn how to transfer the license agreements from one workstation to another, go to
        http://d.android.com/r/studio-ui/export-licenses.html

        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* What went wrong:
        A problem occurred configuring root project 'android'.
        > You have not accepted the license agreements of the following SDK components:
        [Android SDK Platform 25].
        Before building your project, you need to accept the license agreements and complete the installation of the
        missing components using the Android Studio SDK Manager.
        Alternatively, to learn how to transfer the license agreements from one workstation to another, go to
        http://d.android.com/r/studio-ui/export-licenses.html

Sum of these errors are helpful enough if you break them down

This is because you have not accepted the licence agreements, you can choose to open Android Studio SDK Manager and accept them or alternatively you can try this Stackoverflow solution https://stackoverflow.com/questions/40383323/cant-accept-license-agreement-android-sdk-platform-24/40383457#40383457

I try your solution for creating the file of licences manually but this time it output me this error:

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

        (truncated) ... dovaLib:bundleDebug UP-TO-DATE
        :CordovaLib:preReleaseBuild UP-TO-DATE
        :CordovaLib:checkReleaseManifest
        :CordovaLib:prepareReleaseDependencies
        :CordovaLib:compileReleaseAidl UP-TO-DATE
        :CordovaLib:compileReleaseNdk UP-TO-DATE
        :CordovaLib:copyReleaseLint UP-TO-DATE
        :CordovaLib:mergeReleaseShaders UP-TO-DATE
        :CordovaLib:compileReleaseShaders UP-TO-DATE
        :CordovaLib:generateReleaseAssets UP-TO-DATE
        :CordovaLib:mergeReleaseAssets UP-TO-DATE
        :CordovaLib:mergeReleaseProguardFiles UP-TO-DATE
        :CordovaLib:packageReleaseRenderscript UP-TO-DATE
        :CordovaLib:compileReleaseRenderscript UP-TO-DATE
        :CordovaLib:generateReleaseResValues UP-TO-DATE
        :CordovaLib:generateReleaseResources UP-TO-DATE
        :CordovaLib:packageReleaseResources UP-TO-DATE
        :CordovaLib:processReleaseManifest UP-TO-DATE
        :CordovaLib:generateReleaseBuildConfig UP-TO-DATE
        :CordovaLib:processReleaseResources UP-TO-DATE
        :CordovaLib:generateReleaseSources UP-TO-DATE
        :CordovaLib:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
        :CordovaLib:compileReleaseJavaWithJavac UP-TO-DATE
        :CordovaLib:processReleaseJavaRes UP-TO-DATE
        :CordovaLib:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
        :CordovaLib:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
        :CordovaLib:mergeReleaseJniLibFolders UP-TO-DATE
        :CordovaLib:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
        :CordovaLib:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
        :CordovaLib:bundleRelease UP-TO-DATE
        :prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE
        :prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE
        :prepareComAndroidSupportMultidex101Library UP-TO-DATE
        :prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE
        :prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE
        :prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE
        :prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE
        :prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE
        :prepareComAndroidSupportSupportV42421Library UP-TO-DATE
        :prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE
        :prepareComCommonswareCwacCameraCamera06254Library UP-TO-DATE
        :prepareIoScanbotDetector154Library UP-TO-DATE
        :prepareIoScanbotLicensing131Library UP-TO-DATE
        :prepareIoScanbotSdkBase1226Library UP-TO-DATE
        :prepareIoScanbotSdkPackage11226Library UP-TO-DATE
        :prepareIoScanbotSdkPackage21226Library UP-TO-DATE
        :prepareIoScanbotTessTwo112SNAPSHOTLibrary 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
        Error: Failed to crunch file C:\Users\mohmmed dhaif\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master
        (2)\scanbot-sdk-example-ionic2-master\platforms\android\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png
        into C:\Users\mohmmed dhaif\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master
        (2)\scanbot-sdk-example-ionic2-master\platforms\android\build\intermediates\res\merged\debug\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png
        :mergeDebugResources FAILED


        FAILURE: Build failed with an exception.

        * What went wrong:
        Execution failed for task ':mergeDebugResources'.
        > Error: Failed to crunch file C:\Users\mohmmed dhaif\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master
        (2)\scanbot-sdk-example-ionic2-master\platforms\android\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png
        into C:\Users\mohmmed dhaif\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master
        (2)\scanbot-sdk-example-ionic2-master\platforms\android\build\intermediates\res\merged\debug\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png

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

        Total time: 13.368 secs
        Error: cmd: Command failed with exit code 1 Error output:
        FAILURE: Build failed with an exception.

        * What went wrong:
        Execution failed for task ':mergeDebugResources'.
        > Error: Failed to crunch file C:\Users\mohmmed dhaif\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master
        (2)\scanbot-sdk-example-ionic2-master\platforms\android\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png
        into C:\Users\mohmmed dhaif\Desktop\ionic 2\44\scanbot-sdk-example-ionic2-master
        (2)\scanbot-sdk-example-ionic2-master\platforms\android\build\intermediates\res\merged\debug\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png

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

as i can see from above that there is file can’t be crunched… i try to copy this file to specified bath but it won’t work and i don’t know what i suppose to do :stuck_out_tongue:

sorry for putting you with me in this trouble :stuck_out_tongue: :stuck_out_tongue:

The problem is solved… :slight_smile:

i discover that this error is prompted because i have to make the name of the main project folder shorter then it is written… thank you so much for you help :slight_smile:

1 Like