Add android:name="something" to AndroidManifest.xml "application" tag from Cordova plugin.xml

I had the same issue, and I used a Cordova hook to do the work.

First, edit your config.xml file to add the hook:

<platform name="android">
    <hook type="after_prepare" src="scripts/android_app_name.js" />
</platform>

Create a file called scripts/android_app_name.js (set it executable), and inside, just use a search/replace function. It should look like:

#!/usr/bin/env node

module.exports = function(context) {

  var fs = context.requireCordovaModule('fs'),
    path = context.requireCordovaModule('path');

  var platformRoot = path.join(context.opts.projectRoot, 'platforms/android');


  var manifestFile = path.join(platformRoot, 'AndroidManifest.xml');

  if (fs.existsSync(manifestFile)) {

    fs.readFile(manifestFile, 'utf8', function (err,data) {
      if (err) {
        throw new Error('Unable to find AndroidManifest.xml: ' + err);
      }

      var appClass = 'YOU_APP_CLASS';

      if (data.indexOf(appClass) == -1) {

        var result = data.replace(/<application/g, '<application android:name="' + appClass + '"');

        fs.writeFile(manifestFile, result, 'utf8', function (err) {
          if (err) throw new Error('Unable to write into AndroidManifest.xml: ' + err);
        })
      }
    });
  }


};

Indeed, as jlreymendez mentioned, the right way is this:

    <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
      <application android:name="com.mypackage.MyApplication"/>
    </edit-config>

Also note that modifications will revert if you remove the plugin, what will not happen with the hook trick.


The simplest and the latest(cordova version 8.1.2) way to do it to use edit-config tag like below:

    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
        <application android:name="mypackage" />
    </edit-config>

In similar way you can edit other configurations as well.

Hope it will be helpful!