apache/cordova-android · error · CordovaError

Required attribute "src" not specified in <asset> element fr

Error message

Required attribute "src" not specified in <asset> element from plugin: ${plugin.id}

What it means

Thrown by the asset install handler when a plugin's plugin.xml declares <asset> without a src attribute. <asset> copies a www-facing file (JS, CSS, images) from the plugin into the app's www tree, so the source path is mandatory; cordova-android aborts the plugin install when it is missing.

Source

Thrown at lib/pluginHandlers.js:132

                }
            } else {
                obj.type = 'sys';
                subDir = src;
            }

            if (obj.type === 'gradleReference') {
                project.removeGradleReference(parentDir, subDir);
            } else if (obj.type === 'sys') {
                project.removeSystemLibrary(parentDir, subDir);
            } else {
                project.removeSubProject(parentDir, subDir);
            }
        }
    },
    asset: {
        install: function (obj, plugin, project, options) {
            if (!obj.src) {
                throw new CordovaError(generateAttributeError('src', 'asset', plugin.id));
            }
            if (!obj.target) {
                throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
            }

            copyFile(plugin.dir, obj.src, project.www, obj.target);
            if (options && options.usePlatformWww) {
                // CB-11022 copy file to both directories if usePlatformWww is specified
                copyFile(plugin.dir, obj.src, project.platformWww, obj.target);
            }
        },
        uninstall: function (obj, plugin, project, options) {
            const target = obj.target || obj.src;

            if (!target) {
                throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
            }

View on GitHub (pinned to 7c1e190064)

Solutions

  1. Add src to the <asset> element, relative to the plugin root: <asset src="www/foo.js" target="www/foo.js"/>
  2. Verify the file actually exists at that path inside the plugin (see the separate '"..." not found!' error)
  3. Fix upstream and republish the plugin if it ships broken

Example fix

<!-- before -->
<asset target="www/cdv-plugin.js" />

<!-- after -->
<asset src="www/cdv-plugin.js" target="www/cdv-plugin.js" />
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const xml = fs.readFileSync('node_modules/<plugin>/plugin.xml', 'utf8');
if (/<asset(?![^>]*\bsrc=)[^>]*\/>/.test(xml)) {
  throw new Error('<asset> without src — fix plugin.xml before install');
}

Try / catch

try { await cordova.plugin('add', p); } catch (e) {
  if (/Required attribute "src" not specified in <asset>/.test(e.message)) { /* fix plugin.xml asset elements */ }
}

Prevention

When it happens

Trigger: `cordova plugin add <plugin>` where plugin.xml contains <asset target="www/foo.js"/> (target present, src absent). The handler checks !obj.src first and throws generateAttributeError('src','asset',...).

Common situations: Typos such as <asset source="...">; refactoring plugin.xml and deleting the src attribute; HTML/JS assets moved without updating plugin.xml.

Related errors


AI-assisted analysis of apache/cordova-android@7c1e190064 (2026-08-22). Data as JSON: /api/errors/5e1f5682450e2e71. Report an issue: GitHub.