apache / apache/cordova-android

Missing or incomplete platform or plugin folders are ignored by Cordova and result in incomplete builds

Open
#1,731 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.8k
Forks
1.6k
Avg merge
16h 18m
Merged PRs (30d)
11

Description

# Bug Report

## Problem

When I run a cordova build on a fresh git cloned project, after npm install, the following error occurs:

```
Failed to install 'cordova-plugin-statusbar':
Error: C:\path-to-app\platforms\android\cdv-gradle-config.json: ENOENT: no such file or directory,
open 'C:\path-to-app\platforms\android\cdv-gradle-config.json'
```

My workaround, is adding a pre build script which adds the platform again:

```js
if (!existsSync('platforms/android/android.json')) {
const cordovaAndroidVersion = devDependencies['cordova-android'];
execSync(`cordova platform add android@${cordovaAndroidVersion}`, { stdio: 'inherit' });
}
```

But then, sometimes the following error appears:

```
CordovaError: Platform android already added.
at C:\path-to-app\node_modules\cordova-lib\src\cordova\platform\addHelper.js:120:35
```

### Command or Code

```
cordova build android --release
```

I think we should ensure that the platform incl. folder structure exists on npm i or cordova build. Because it's already defined in package.json.

### Environment, Platform, Device

Windows 11, Node 20.14, cordova-android 13

## Checklist

- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start with the platform-add path in node_modules/cordova-lib/src/cordova/platform/addHelper.js around line 120, then inspect the project package.json and the build command shown in the report. Reproduce the fresh-clone case on the stated Windows/Node/Cordova Android setup and compare missing or partially present platform folders; done means builds no longer fail or report that an already-added platform is being added.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript, nodejs
Domain
build-system, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.