FAILURE:Build failed with an exception


#1

While trying with ionic cordova build android getting FAILURE: Build failed with an exception.


#2

set version 25.+ in project.properties file.

com.android.support:support-v4:25.+

if it still throws an error. try updating it from sdk manager.


#3

followed the mentioned steps … Still facing the same issue…


#4

try clean npm cache

npm cache clean -f

make changes to porject.properties.

com.android.support:support-v4:9.0.0

Then build your android app. It should download the required .jar and .pom files. Check your build.gradle for following code.

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
    }
}

This should be there in your gradle file.

For Example, my build.gradle looks like

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    //This replaces project.properties w.r.t. build settings
    project.ext {
      defaultBuildToolsVersion="25.0.2" //String
      defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
      defaultTargetSdkVersion=26 //Integer - We ALWAYS target the latest by default
      defaultCompileSdkVersion=26 //Integer - We ALWAYS compile with the latest by default
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

>ionic info

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

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

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:

    Android SDK Tools : 25.2.5
    Node              : v8.9.0
    npm               : 5.8.0
    OS                : Windows 8.1

Environment Variables:

    ANDROID_HOME : C:\Users\UserXx\android-sdks

Misc:

    backend : pro

#5

Tried with the mentioned steps still facing the same issue. Here is my ionic info:

F:\bikecrashsensing>ionic info

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

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0

local packages:

@ionic/app-scripts : 1.3.12
Cordova Platforms  : android 7.0.0
Ionic Framework    : ionic-angular 3.5.0

System:

Android SDK Tools : 26.1.1
Node              : v8.9.4
npm               : 5.7.1
OS                : Windows 7

Environment Variables:

ANDROID_HOME : C:\Users\USER\AppData\Local\Android\Sdk

Misc:

backend : pro

Here is the Stack Trace :

F:\bikecrashsensing>ionic cordova build android
[WARN] Detected @ionic/cli-plugin-cordova in your package.json.

   As of CLI 3.8, it is no longer needed. You can uninstall it:

   npm uninstall -D @ionic/cli-plugin-cordova

[WARN] Detected @ionic/cli-plugin-ionic-angular in your package.json.

   As of CLI 3.8, it is no longer needed. You can uninstall it:

   npm uninstall -D @ionic/cli-plugin-ionic-angular

Running app-scripts build: --platform android --target cordova
[12:18:58] build dev started …
[12:18:58] clean started …
[12:18:58] clean finished in 3 ms
[12:18:58] copy started …
[12:18:58] transpile started …
[12:19:01] transpile finished in 2.68 s
[12:19:01] preprocess started …
[12:19:01] deeplinks started …
[12:19:01] deeplinks finished in 32 ms
[12:19:01] preprocess finished in 33 ms
[12:19:01] webpack started …
[12:19:01] copy finished in 2.85 s
[12:19:10] webpack finished in 9.46 s
[12:19:10] sass started …
[12:19:12] sass finished in 1.36 s
[12:19:12] postprocess started …
[12:19:12] removed unused font files
[12:19:12] postprocess finished in 8 ms
[12:19:12] lint started …
[12:19:12] build dev finished in 13.63 s

cordova build android
Android Studio project detected

ANDROID_HOME=C:\Users\USER\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
studio
Subproject Path: CordovaLib
Subproject Path: app
[12:19:21] tslint: F:/bikecrashsensing/src/pages/device-details/device-details.ts, line: 5
All imports are unused.

   L4:  import {ChangeDetectorRef }from '@angular/core';
   L5:  import {Autosize}from 'ionic2-autosize';

[12:19:21] tslint: F:/bikecrashsensing/src/pages/home/home.ts, line: 34
‘ondev’ is declared but never used.

  L33:  console.log("in ble scan");
  L34:  let ondev =  {
  L35:  "id":"908790a-ad23-ada2423",

[12:19:21] lint finished in 9.15 s

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘F:\bikecrashsensing\platforms\android\build.gradle’ line: 37

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

Could not find method compile() for arguments [project ‘:CordovaLib’] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

  • 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 4s
(node:5468) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • Where:
    Build file ‘F:\bikecrashsensing\platforms\android\build.gradle’ line: 37

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

Could not find method compile() for arguments [project ‘:CordovaLib’] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

  • 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 4s
(node:5468) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.