Can't build android with capacitor

I’ve created new clean app with capacitor and trying to build it using appflow but getting error “android platform has not been added yet”

I don’t see “npx cap add android” in the logs

what I’m doing wrong?

Build Stack: Linux - 2021.09
Cordova CLI 10.0.0
Ionic CLI 6.17.1
Node.js 14.17.6
Node.js versions 10.24.1 / 12.22.6 / 14.17.6
npm 6.14.15
Yarn 1.22.11
Python 2 / 3
Debian 11.0
Gradle 4.3.1
OpenJDK 1.8.0_265 and 11.0.12
Android SDK 27-30
logs

Running with gitlab-runner 11.3.1 (0aa5179e)
on Ionic Package Android Runner f537d27d
Using Kubernetes namespace: ionic-runners
Using Kubernetes executor with image 319312831725.dkr.ecr.us-west-2.amazonaws.com/appflow-runners/linux:2021.09
Waiting for pod ionic-runners/runner-f537d27d-project-0-concurrent-26tncl to be running, status is Pending
Running on runner-f537d27d-project-0-concurrent-26tncl via gitlab-runner-55f5c4f79c-lwc9b…
Cloning repository…
Cloning into ‘/builds/x/pc’…
Checking out f0bbab89 as test…
Updating/initializing submodules…
$ run “fetch-updates”
$ run “build-android”
/builds/x/pc/fastlane/actions/build_android_cordova.rb:6: warning: already initialized constant Fastlane::Actions::SharedValues::APK_FILE_PATH
/builds/x/pc/fastlane/actions/build_android_capacitor.rb:6: warning: previous definition of APK_FILE_PATH was here
/builds/x/pc/fastlane/actions/build_android_cordova.rb:7: warning: already initialized constant Fastlane::Actions::SharedValues::AAB_FILE_PATH
/builds/x/pc/fastlane/actions/build_android_capacitor.rb:7: warning: previous definition of AAB_FILE_PATH was here
/builds/x/pc/fastlane/actions/download_package.rb:4: warning: already initialized constant Fastlane::Actions::SharedValues::APK_FILE_PATH
/builds/x/pc/fastlane/actions/build_android_cordova.rb:6: warning: previous definition of APK_FILE_PATH was here
/builds/x/pc/fastlane/actions/download_package.rb:5: warning: already initialized constant Fastlane::Actions::SharedValues::AAB_FILE_PATH
/builds/x/pc/fastlane/actions/build_android_cordova.rb:7: warning: previous definition of AAB_FILE_PATH was here
/builds/x/pc/fastlane/actions/upload_android_files.rb:4: warning: already initialized constant Fastlane::Actions::SharedValues::APK_FILE_PATH
/builds/x/pc/fastlane/actions/download_package.rb:4: warning: previous definition of APK_FILE_PATH was here
/builds/x/pc/fastlane/actions/upload_android_files.rb:5: warning: already initialized constant Fastlane::Actions::SharedValues::AAB_FILE_PATH
/builds/x/pc/fastlane/actions/download_package.rb:5: warning: previous definition of AAB_FILE_PATH was here
/builds/x/pc/fastlane/actions/upload_binary_to_play_store.rb:4: warning: already initialized constant Fastlane::Actions::SharedValues::APK_FILE_PATH
/builds/x/pc/fastlane/actions/upload_android_files.rb:4: warning: previous definition of APK_FILE_PATH was here
/builds/x/pc/fastlane/actions/upload_binary_to_play_store.rb:5: warning: already initialized constant Fastlane::Actions::SharedValues::AAB_FILE_PATH
/builds/x/pc/fastlane/actions/upload_android_files.rb:5: warning: previous definition of AAB_FILE_PATH was here
[12:25:21]: ------------------------------
[12:25:21]: — Step: default_platform —
[12:25:21]: ------------------------------
[12:25:21]: Driving the lane ‘android package_build’ :rocket:
12:25:23: ---------------------------
12:25:23: — Step: build_summary —
12:25:23: ---------------------------

±--------------------±----------------------------+
| Build Summary |
±--------------------±----------------------------+
| Job ID | 8006935 |
| Node.js version | v14.17.6 |
| Cordova CLI version | 10.0.0 (cordova-lib@10.1.0) |
| npm version | 6.14.15 |
±--------------------±----------------------------+

12:25:23: — Step: add_git_credentials —
12:25:23: ---------------------------------
12:25:23: Writing git-credentials files
12:25:23: git-credentials successfully added to project
12:25:23: --------------------------------
12:25:23: — Step: get_appflow_config —
12:25:23: --------------------------------
12:25:23: Checking for appflow.config.json
12:25:23: Appflow config not detected
12:25:23: --------------------------------
12:25:23: — Step: detect_native_type —
12:25:23: --------------------------------
12:25:23: Checking if cordova or capacitor project
12:25:23: Capacitor project with JSON config detected
12:25:23: --------------------------------
12:25:23: — Step: dependency_install —
12:25:23: --------------------------------
12:25:23: Installing Dependencies
12:25:23: $ npm ci --quiet --no-optional
[12:26:05]: ▸ > nice-napi@1.0.2 install /builds/x/pc/node_modules/nice-napi
[12:26:05]: ▸ > node-gyp-build
[12:26:05]: ▸ > esbuild@0.14.22 postinstall /builds/x/pc/node_modules/@angular-devkit/build-angular/node_modules/esbuild
[12:26:05]: ▸ > node install.js
[12:26:05]: ▸ > core-js@3.20.3 postinstall /builds/x/pc/node_modules/core-js
[12:26:05]: ▸ > node -e “try{require(’./postinstall’)}catch(e){}”
[12:26:06]: ▸ > @angular/cli@13.2.6 postinstall /builds/x/pc/node_modules/@angular/cli
[12:26:06]: ▸ > node ./bin/postinstall/script.js
[12:26:06]: ▸ > core-js-pure@3.22.7 postinstall /builds/x/pc/node_modules/core-js-pure
[12:26:06]: ▸ > node -e “try{require(’./postinstall’)}catch(e){}”
[12:26:06]: ▸ > @parcel/watcher@2.0.4 install /builds/x/pc/node_modules/@parcel/watcher
[12:26:06]: ▸ > node-gyp-build
[12:26:06]: ▸ > nx@14.1.9 postinstall /builds/x/pc/node_modules/@nrwl/cli/node_modules/nx
[12:26:06]: ▸ > node ./bin/init
[12:26:07]: ▸ added 1310 packages in 43.282s
[12:26:07]: -------------------------------------
[12:26:07]: — Step: create_capacitor_config —
[12:26:07]: -------------------------------------
[12:26:07]: -------------------------
[12:26:07]: — Step: get_web_dir —
[12:26:07]: -------------------------
[12:26:07]: webDir is www
[12:26:07]: ---------------------------
[12:26:07]: — Step: set_java_home —
[12:26:07]: ---------------------------
[12:26:07]: Try to detect the android gradle plugin version in a Capacitor project
[12:26:07]: android/build.gradle file not found in the project: using default Java version
[12:26:07]: -----------------------------------
[12:26:07]: — Step: modify_cap_web_config —
[12:26:07]: -----------------------------------
[12:26:07]: No custom native config detected.
[12:26:07]: ---------------------------------
[12:26:07]: — Step: download_credential —
[12:26:07]: ---------------------------------
[12:26:07]: Downloading build credentials…
[12:26:08]: Successfully downloaded build credentials.
[12:26:08]: Saving build credentials…
[12:26:08]: Successfully saved build credentials.
[12:26:08]: ---------------------------
[12:26:08]: — Step: build_pro_app —
[12:26:08]: ---------------------------
[12:26:08]: Build script detected…
[12:26:08]: $ npm run build
[12:26:08]: ▸ > myApp@0.0.1 build /builds/x/pc
[12:26:08]: ▸ > ng build
[12:26:11]: ▸ - Generating browser application bundles (phase: setup)…
[12:26:31]: ▸ :heavy_check_mark: Browser application bundle generation complete.
[12:26:31]: ▸ :heavy_check_mark: Browser application bundle generation complete.
[12:26:31]: ▸ - Copying assets…
[12:26:31]: ▸ :heavy_check_mark: Copying assets complete.
[12:26:31]: ▸ - Generating index html…
[12:26:31]: ▸ :heavy_check_mark: Index html generation complete.
[12:26:31]: ▸ Initial Chunk Files | Names | Raw Size
[12:26:31]: ▸ vendor.js | vendor | 3.54 MB |
[12:26:31]: ▸ polyfills.js | polyfills | 307.57 kB |
[12:26:31]: ▸ styles.css | styles | 37.80 kB |
[12:26:31]: ▸ main.js | main | 14.40 kB |
[12:26:31]: ▸ runtime.js | runtime | 13.96 kB |
[12:26:31]: ▸
[12:26:31]: ▸ | Initial Total | 3.91 MB
[12:26:31]: ▸
[12:26:31]: ▸ Lazy Chunk Files | Names | Raw Size
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_swiper_bundle-28080340_js.js | swiper-bundle-28080340-js | 200.26 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-datetime_3_entry_js.js | - | 142.43 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-item_8_entry_js.js | - | 94.09 kB |
[12:26:31]: ▸ polyfills-core-js.js | polyfills-core-js | 92.34 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-app_8_entry_js.js | - | 76.67 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-modal_entry_js.js | - | 69.70 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-slide_2_entry_js.js | - | 60.05 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-popover_entry_js.js | - | 57.88 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-refresher_2_entry_js.js | - | 51.88 kB |
[12:26:31]: ▸ common.js | common | 49.52 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-alert_entry_js.js | - | 47.40 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-segment_2_entry_js.js | - | 40.68 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-menu_3_entry_js.js | - | 38.99 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-nav_2_entry_js.js | - | 35.64 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-item-option_3_entry_js.js | - | 34.21 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-searchbar_entry_js.js | - | 34.16 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-button_2_entry_js.js | - | 33.86 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-route_4_entry_js.js | - | 32.84 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-select_3_entry_js.js | - | 31.78 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-action-sheet_entry_js.js | - | 30.45 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-range_entry_js.js | - | 29.05 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-accordion_2_entry_js.js | - | 27.15 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-fab_3_entry_js.js | - | 27.13 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-tab-bar_2_entry_js.js | - | 24.02 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-toast_entry_js.js | - | 23.57 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-input_entry_js.js | - | 22.85 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-breadcrumb_2_entry_js.js | - | 22.19 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-progress-bar_entry_js.js | - | 21.98 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-picker-internal_entry_js.js | - | 21.46 kB |
[12:26:31]: ▸ polyfills-dom.js | polyfills-dom | 19.42 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-textarea_entry_js.js | - | 19.41 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-virtual-scroll_entry_js.js | - | 19.33 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-toggle_entry_js.js | - | 17.82 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-back-button_entry_js.js | - | 17.26 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_input-shims-9f58f9e5_js.js | input-shims-9f58f9e5-js | 17.09 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-radio_2_entry_js.js | - | 16.94 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-col_3_entry_js.js | - | 15.80 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-card_5_entry_js.js | - | 15.63 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-loading_entry_js.js | - | 15.23 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-infinite-scroll_2_entry_js.js | - | 14.13 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-picker-column-internal_entry_js.js | - | 13.51 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-reorder_2_entry_js.js | - | 13.29 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-checkbox_entry_js.js | - | 11.45 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-split-pane_entry_js.js | - | 10.11 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-chip_entry_js.js | - | 9.85 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-tab_2_entry_js.js | - | 9.70 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-spinner_entry_js.js | - | 8.15 kB |
[12:26:31]: ▸ src_app_tabs_tabs_module_ts.js | tabs-tabs-module | 6.98 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-ripple-effect_entry_js.js | - | 6.63 kB |
[12:26:31]: ▸ src_app_tab3_tab3_module_ts.js | tab3-tab3-module | 6.33 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_tap-click-44cde579_js.js | tap-click-44cde579-js | 6.22 kB |
[12:26:31]: ▸ src_app_tab1_tab1_module_ts.js | tab1-tab1-module | 6.06 kB |
[12:26:31]: ▸ src_app_tab2_tab2_module_ts.js | tab2-tab2-module | 6.06 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-avatar_3_entry_js.js | - | 5.83 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-img_entry_js.js | - | 4.54 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-backdrop_entry_js.js | - | 3.47 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_status-tap-52d42f39_js.js | status-tap-52d42f39-js | 2.89 kB |
[12:26:31]: ▸ node_modules_ionic_core_dist_esm_ion-text_entry_js.js | - | 1.76 kB |
[12:26:31]: ▸
[12:26:31]: ▸ Build at: 2022-05-30T12:26:31.641Z - Hash: be4d10fa58d3fc26 - Time: 20074ms
[12:26:31]: $ ionic info
[12:26:32]: ▸ [WARN] Error loading @capacitor/ios package.json: Error: Cannot find module ‘@capacitor/ios/package’
[12:26:32]: ▸ Require stack:
[12:26:32]: ▸ - /usr/local/nvm/versions/node/v14.17.6/lib/node_modules/@ionic/cli/lib/project/index.js
[12:26:32]: ▸ - /usr/local/nvm/versions/node/v14.17.6/lib/node_modules/@ionic/cli/lib/index.js
[12:26:32]: ▸ - /usr/local/nvm/versions/node/v14.17.6/lib/node_modules/@ionic/cli/index.js
[12:26:32]: ▸ - /usr/local/nvm/versions/node/v14.17.6/lib/node_modules/@ionic/cli/bin/ionic
[12:26:32]: ▸ Ionic:
[12:26:32]: ▸ Ionic CLI : 6.17.1 (/usr/local/nvm/versions/node/v14.17.6/lib/node_modules/@ionic/cli)
[12:26:32]: ▸ Ionic Framework : @ionic/angular 6.1.7
[12:26:32]: ▸ @angular-devkit/build-angular : 13.2.6
[12:26:32]: ▸ @angular-devkit/schematics : 13.2.6
[12:26:32]: ▸ @angular/cli : 13.2.6
[12:26:32]: ▸ @ionic/angular-toolkit : 6.1.0
[12:26:32]: ▸ Capacitor:
[12:26:32]: ▸ Capacitor CLI : 3.5.1
[12:26:32]: ▸ @capacitor/android : 3.5.1
[12:26:32]: ▸ @capacitor/core : 3.5.1
[12:26:32]: ▸ @capacitor/ios : not installed
[12:26:32]: ▸ Utility:
[12:26:32]: ▸ cordova-res : not installed globally
[12:26:32]: ▸ native-run : 1.6.0
[12:26:32]: ▸ System:
[12:26:32]: ▸ NodeJS : v14.17.6 (/usr/local/nvm/versions/node/v14.17.6/bin/node)
[12:26:32]: ▸ npm : 6.14.15
[12:26:32]: ▸ OS : Linux 5.4
[12:26:32]: Generating app manifest…
[12:26:32]: $ ionic deploy manifest
[12:26:34]: ▸ [OK] Appflow Deploy manifest written to ./www/pro-manifest.json!
[12:26:34]: ----------------------
[12:26:34]: — Step: cap_sync —
[12:26:34]: ----------------------
[12:26:34]: $ npx cap sync android
[12:26:34]: ▸ [error] android platform has not been added yet.
[12:26:34]: ▸ See the docs for adding the android platform: Capacitor - build cross platform apps with the web
[12:26:34]: -------------------------
[12:26:34]: — Step: upload_logs —
[12:26:34]: -------------------------
±---------------------------±------------------------------------------------+
| Lane Context |
±---------------------------±------------------------------------------------+
| DEFAULT_PLATFORM | ios |
| PLATFORM_NAME | android |
| LANE_NAME | android package_build |
| PROJECT_WEB_DIR | www |
| DOWNLOAD_CREDENTIAL_EXISTS | true |
| DOWNLOAD_CREDENTIAL_PATH | /builds/x/pc/android.keystore |
| DOWNLOAD_CREDENTIAL_ALIAS | pc |
±---------------------------±------------------------------------------------+
[12:26:42]: Exit status of command ‘npx cap sync android’ was 1 instead of 0.
[error] android platform has not been added yet.
See the docs for adding the android platform: Capacitor - build cross platform apps with the web

±-----±------------------------±------------+
| fastlane summary |
±-----±------------------------±------------+
| Step | Action | Time (in s) |
±-----±------------------------±------------+
| 1 | default_platform | 0 |
| 2 | build_summary | 0 |
| 3 | add_git_credentials | 0 |
| 4 | get_appflow_config | 0 |
| 5 | detect_native_type | 0 |
| 6 | dependency_install | 43 |
| 7 | create_capacitor_config | 0 |
| 8 | get_web_dir | 0 |
| 9 | set_java_home | 0 |
| 10 | modify_cap_web_config | 0 |
| 11 | download_credential | 0 |
| 12 | build_pro_app | 25 |
| :boom: | cap_sync | 0 |
| 14 | upload_logs | 7 |
±-----±------------------------±------------+

[12:26:42]: fastlane finished with errors
/usr/local/bundle/bin/fastlane: \e[31m[!] Exit status of command ‘npx cap sync android’ was 1 instead of 0. (FastlaneCore::Interface::FastlaneShellError)
\e[31m[error]\e[39m \e[1mandroid\e[22m platform has not been added yet.
See the docs for adding the \e[1mandroid\e[22m platform: \e[1mhttps://capacitorjs.com/docs/android#adding-the-android-platform\e[22m
\e[0m
Running after script…
$ run “clean-up”
ERROR: Job failed: command terminated with exit code 1

Hi @red_phoenix_apps,

This error usually happens in capacitor projects when the android/ dir is missing from the project. Unlike Cordova, Capacitor projects include the native platform as a source artifact. Please verify that your android/ dir is staged and committed then try a new build.

Here are some steps you can follow:

Make sure your platform directory is not included in your .gitignore
run npm run build
run npx cap add android
run npx cap sync
push a commit and try a build from that commit

If the issue persists please reach out to Appflow support for further assistance. Thanks!

1 Like