A problem occurred configuring root project 'android'. > Cannot add task ':processDebugGoogleServices' as a task with that name already exists

When I run ionic cordova build android
I get this.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Cannot add task ':processDebugGoogleServices' as a task with that name already exists.

* 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
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'.
> Cannot add task ':processDebugGoogleServices' as a task with that name already exists.

* 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
[ERROR] An error occurred while running subprocess cordova.

        cordova build android exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.


ionic info

Ionic:

   ionic (Ionic CLI)  : 4.7.0 (C:\Users\Nilesh\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.8

Cordova:

   cordova (Cordova CLI) : 8.1.1 (cordova-lib@8.1.0)
   Cordova Platforms     : android 6.4.0
   Cordova Plugins       : not available

System:

   Android SDK Tools : 26.1.1 (C:\Users\Nilesh\AppData\Local\Android\Sdk)
   NodeJS            : v6.17.1 (C:\Program Files\nodejs\node.exe)
   npm               : 6.9.0
   OS                : Windows 10

the package.json file:

{
  "name": "myApp",
  "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": "node script.js && ionic-app-scripts serve",
    "ionic:watch:before": "node script.js",
    "ionic:build:before": "node script.js",
    "build:prod": "cross-env ENV=dev ionic cordova build android --prod --release"
  },
  "dependencies": {
    "@angular/animations": "^5.2.10",
    "@angular/common": "5.0.3",
    "@angular/compiler": "5.0.3",
    "@angular/compiler-cli": "5.0.3",
    "@angular/core": "5.0.3",
    "@angular/forms": "5.0.3",
    "@angular/http": "5.0.3",
    "@angular/platform-browser": "5.0.3",
    "@angular/platform-browser-dynamic": "5.0.3",
    "@angular/platform-server": "5.2.2",
    "@angular/router": "5.2.2",
    "@ionic-native/action-sheet": "^4.7.0",
    "@ionic-native/android-permissions": "^4.7.0",
    "@ionic-native/camera": "^4.7.0",
    "@ionic-native/core": "4.4.0",
    "@ionic-native/fcm": "^4.7.0",
    "@ionic-native/file": "^4.7.0",
    "@ionic-native/file-chooser": "^4.7.0",
    "@ionic-native/file-path": "^4.7.0",
    "@ionic-native/file-picker": "^4.12.0",
    "@ionic-native/file-transfer": "^4.7.0",
    "@ionic-native/image-picker": "^4.16.0",
    "@ionic-native/in-app-browser": "^4.20.0",
    "@ionic-native/keyboard": "^4.7.0",
    "@ionic-native/network": "^4.7.0",
    "@ionic-native/splash-screen": "4.4.0",
    "@ionic-native/sqlite": "^4.7.0",
    "@ionic-native/status-bar": "^4.11.0",
    "@ionic-native/video-editor": "^4.20.0",
    "@ionic/pro": "1.0.20",
    "@ionic/storage": "2.1.3",
    "@types/jasmine": "2.2.30",
    "@types/selenium-webdriver": "2.44.26",
    "amazing-time-picker": "^1.5.3",
    "amazon-cognito-identity-js": "1.29.0",
    "aws-sdk": "2.67.0",
    "body-parser": "~1.15.1",
    "calender": "^1.0.3",
    "codelyzer": "4.0.1",
    "com.synconset.imagepicker": "^2.1.10",
    "cookie-parser": "~1.4.3",
    "cordova-android": "6.4.0",
    "cordova-android-support-gradle-release": "^2.1.0",
    "cordova-ios": "4.5.4",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-android-permissions": "^1.0.0",
    "cordova-plugin-camera": "^4.0.3",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-fcm": "^2.1.2",
    "cordova-plugin-file": "^6.0.1",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-filechooser": "^1.2.0",
    "cordova-plugin-filepath": "^1.5.5",
    "cordova-plugin-filepicker": "^1.1.6",
    "cordova-plugin-inappbrowser": "^3.0.0",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^1.2.1",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-video-editor": "^1.1.3",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-sqlite-storage": "^2.6.0",
    "core-js": "2.4.1",
    "debug": "~2.2.0",
    "ejs": "^2.5.2",
    "enhanced-resolve": "^3.3.0",
    "express": "~4.13.4",
    "extract-text-webpack-plugin": "2.1.0",
    "ionic-angular": "3.9.2",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionic-tooltips": "^2.0.1",
    "ionicons": "3.0.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "jwt-decode": "^2.2.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.0.2",
    "karma-remap-istanbul": "0.6.0",
    "moment": "^2.22.1",
    "morgan": "~1.7.0",
    "ng2-datepicker": "^2.2.5",
    "ngx-filter-pipe": "^2.1.0",
    "ngx-permissions": "^4.1.0",
    "protractor": "5.1.1",
    "rxjs": "5.5.2",
    "serve-favicon": "~2.3.0",
    "sw-toolbox": "3.6.0",
    "ts-helpers": "1.1.1",
    "ts-node": "3.2.0",
    "tslint": "5.7.0",
    "typescript": "2.4.2",
    "webpack": "2.2.1",
    "webpack-dev-middleware": "1.10.1",
    "webpack-dev-server": "2.4.2",
    "webpack-md5-hash": "0.0.5",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.8",
    "@types/node": "^8.9.4",
    "typescript": "2.4.2",
    "cross-env": "5.2.0",
    "nodemon": "^1.18.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-file-transfer": {},
      "cordova-plugin-file": {},
      "cordova-sqlite-storage": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-filechooser": {},
      "cordova-plugin-camera": {},
      "cordova-plugin-actionsheet": {},
      "cordova-plugin-android-permissions": {},
      "cordova-plugin-filepath": {},
      "com.synconset.imagepicker": {
        "PHOTO_LIBRARY_USAGE_DESCRIPTION": "your usage message"
      },
      "cordova-plugin-fcm": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-filepicker": {},
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "26.+"
      },
      "cordova-plugin-video-editor": {},
      "cordova-plugin-inappbrowser": {}
    },
    "platforms": [
      "ios",
      "android"
    ]
  }
}

cordova plugin info

com.synconset.imagepicker 2.1.8 "ImagePicker"
cordova-android-support-gradle-release 2.1.0 "cordova-android-support-gradle-release"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-android-permissions 1.0.0 "Permissions"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-fcm 2.1.2 "FCMPlugin"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-filechooser 1.2.0 "File Chooser"
cordova-plugin-filepath 1.5.5 "cordova-plugin-filepath"
cordova-plugin-filepicker 1.1.6 "File Picker"
cordova-plugin-firebase 2.0.5 "Google Firebase Plugin"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-video-editor 1.1.3 "VideoEditor"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-sqlite-storage 2.6.0 "Cordova sqlite storage plugin"

I have been stuck on this for too long now. Tried editing the gradle files according to some solutions but to no avail