Ionic cordova android platform won't add

I am having a nightmare as always with npm packages and ionic / cordova. I run:

ionic cordova platform add android

And i get this error:

Cannot overwrite directory
‘/Volumes/Work/Projects/green-water-services/platforms/android/app/src/main’
with non-directory
‘/Volumes/Work/Projects/green-water-services/plugins/cordova-plugin-firebase/src/android/google-services.json’.

I have no idea what it’s doing! Here is my package:

{
  "name": "green-water-services",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^11.2.14",
    "@angular/core": "^11.2.14",
    "@angular/fire": "^6.1.5",
    "@angular/forms": "^11.2.14",
    "@angular/platform-browser": "^11.2.14",
    "@angular/platform-browser-dynamic": "^11.2.14",
    "@angular/router": "^11.2.14",
    "@ionic-native/ble": "^5.6.11",
    "@ionic-native/bluetooth-serial": "^5.6.11",
    "@ionic-native/camera": "^5.6.11",
    "@ionic-native/core": "^5.6.11",
    "@ionic-native/firebase": "^5.6.11",
    "@ionic/angular": "^5.6.11",
    "@ionic/app-scripts": "^3.2.4",
    "cordova-plugin-bluetooth-serial": "^0.4.7",
    "firebase": "^8.6.8",
    "ionic": "^5.4.16",
    "ionicons": "^5.5.2",
    "npm": "^8.3.0",
    "rxjs": "~6.6.0",
    "rxjs-compat": "^6.6.7",
    "signature_pad": "^4.0.1",
    "tslib": "^2.3.0",
    "typescript": "4.1.6",
    "zone.js": "^0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^12.1.0",
    "@angular-eslint/builder": "2.0.2",
    "@angular-eslint/eslint-plugin": "2.0.2",
    "@angular-eslint/eslint-plugin-template": "2.0.2",
    "@angular-eslint/template-parser": "2.0.2",
    "@angular/cli": "11.2.14",
    "@angular/compiler": "^11.2.14",
    "@angular/compiler-cli": "^11.2.14",
    "@angular/language-service": "^11.2.14",
    "@ionic/angular-toolkit": "^3.1.1",
    "@types/jasmine": "^3.7.7",
    "@types/jasminewd2": "^2.0.9",
    "@types/node": "^12.20.15",
    "@typescript-eslint/eslint-plugin": "4.16.1",
    "@typescript-eslint/parser": "4.16.1",
    "cordova-android": "^10.1.1",
    "cordova-plugin-ble-central": "^1.3.1",
    "cordova-plugin-camera": "^5.0.2",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-firebase": "^2.0.5",
    "cordova-plugin-firebase-lib": "^5.1.1",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.2.1",
    "cordova-plugin-splashscreen": "^5.0.4",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-whitelist": "^1.3.5",
    "eslint": "^7.29.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "firebase-tools": "^9.14.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "^6.3.4",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.6.0",
    "postcss": "^8.4.5",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-bluetooth-serial": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-ble-central": {
        "ACCESS_BACKGROUND_LOCATION": "false"
      },
      "cordova-plugin-firebase": {},
      "cordova-plugin-camera": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      }
    },
    "platforms": []
  }
}

Output of ng version is:

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1202.14
@angular-devkit/build-angular   12.2.14
@angular-devkit/core            12.2.14
@angular-devkit/schematics      11.2.14
@angular/fire                   6.1.5
@schematics/angular             11.2.14
@schematics/update              0.1102.14
rxjs                            6.6.7
typescript                      4.1.6

It works fine when serving or running to a device, but as soon as i try to build it errors happen all over. Does anyone have any idea what is going on?

your error states it cannot overwrite a directory. Just remove the platforms, plugins folders and run npm i. then add the platforms back.

Also if you run --verbose flag when trying to build for a platform, it will give you more detail about any errors.

I’ve done all that, when i try to add the platform back it gives me that weird error

It looks like it’s something to do with firebase not liking cordova 9, so i have done:

ionic cordova platform add android@8.0.0

And that has gone through, but now when i build it with ionic cordova build android i get so far and then this happens:

Task :app:preBuild UP-TO-DATE
Task :CordovaLib:preBuild UP-TO-DATE
Task :CordovaLib:preDebugBuild UP-TO-DATE
Task :CordovaLib:checkDebugManifest
Task :CordovaLib:processDebugManifest
Task :app:preDebugBuild
Task :app:preDebugBuild FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Failed to capture fingerprint of input files for task ‘:app:preDebugBuild’ property ‘compileManifests’ during up-to-date check.
    The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[20.0.1,20.0.1], [20.0.2,20.0.2]], but resolves to 20.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

3 actionable tasks: 3 executed

BUILD FAILED in 2m 10s
/Volumes/Work/green-water-services/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    Failed to capture fingerprint of input files for task ‘:app:preDebugBuild’ property ‘compileManifests’ during up-to-date check.
    The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[20.0.1,20.0.1], [20.0.2,20.0.2]], but resolves to 20.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2m 10s
[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.

I have no idea what this means! This is absolutely ridiculous, it all works when live running on a device.