"Error: Platform android already added." when running running build

Hello,

currently I’m trying to build a sample project for android.

When I run the following command

ionic cordova build --release android

I get the following error:

:heavy_multiplication_x: Running command - failed!
[ERROR] An error occurred while running cordova platform add --save android (exit code 1):

    Running command: /home/marcel/hooks/before_platform_add/init_directories.js /home/marcel
    Using cordova-fetch for cordova-android@^6.2.3
    Error: Platform android already added.

I tried to google my error message and searched here a bit, but I couldn’t find a thread that is related to my error. I also hope this is in the right category.

My current envoirment is the Ubuntu container inside windows.
I followed this instructions https://docs.google.com/document/d/1dQU6o-fANkmdIjZR45TAdnj1wWx-BMDDuOnsYqiXluA/edit#heading=h.snch1h76frsj for setting up

Would be really nice if someone could help me with that :slight_smile:

Edit: After removing android as a platform with

cordova platform rm android

and rerunning the build command
I get this error:

[ERROR] An error occurred while running cordova platform add --save android (exit code 1):

    Running command: /home/marcel/hooks/before_platform_add/init_directories.js /home/marcel
    Using cordova-fetch for cordova-android@~6.2.2
    Adding android project...
    Creating Cordova project for the Android platform:
    Path: platforms/android
    Package: com.startapplabs.ionWordpress
    Name: ionWordpress
    Activity: MainActivity
    Android target: android-25
    Subproject Path: CordovaLib
    Android project created with cordova-android@6.2.3
    Running command: /home/marcel/hooks/before_prepare/01_jshint.js /home/marcel
    module.js:471
    throw err;
    ^

    Error: Cannot find module 'jshint'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/marcel/hooks/before_prepare/01_jshint.js:5:31)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    Error: Hook failed with error code 1: /home/marcel/hooks/before_prepare/01_jshint.js

After install the module with

npm install jshint

This error disappear and the initial error occurs

1 Like

Please delete the platforms folder manually then run add platform again :slight_smile:

Use this

cordova platform rm android

or ios in case of ios

Then readd it again

cordova platform add android