如何将xmlns(XML名称空间)添加到android清单头

如何将xmlns(XML名称空间)添加到android清单头,android,cordova,ionic-framework,android-manifest,xml-namespaces,Android,Cordova,Ionic Framework,Android Manifest,Xml Namespaces,我用的是离子框架,我用的是 <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://sche

我用的是离子框架,我用的是

        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
            <application android:allowBackup="false" tools:replace="android:allowBackup" />
            <application android:fullBackupOnly="false" />
        </edit-config>

避免android应用程序中的备份服务

我在
config.xml
中添加了它,它会自动添加到清单中,但是
xmlns:tools=”http://schemas.android.com/tools“
需要手动添加到清单中,否则生成失败并引发错误:

与元素类型“应用程序”关联的属性“tools:replace”的前缀“tools”未绑定。


是否有任何方法可以将配置文件中的
xmlns
自动添加到android清单中?

您可以使用钩子脚本添加名称空间。例如,在Cordova项目中,创建
挂钩/add_tools_namespace.js

#!/usr/bin/env node

const fs = require('fs'),
    path = require('path');

module.exports = function (context) {
    const toolsAttribute = "xmlns:tools=\"http://schemas.android.com/tools\"";
    const manifestOpen = "<manifest";

    const manifestPath = path.join(context.opts.projectRoot, 'platforms/android/app/src/main/AndroidManifest.xml');
    let manifest = fs.readFileSync(manifestPath).toString();

    if(manifest.indexOf(toolsAttribute) == -1) {
        manifest = manifest.replace(manifestOpen, manifestOpen + " " + toolsAttribute + " ");
        fs.writeFileSync(manifestPath, manifest, 'utf8');
    }
};

可以使用钩子脚本添加名称空间。例如,在Cordova项目中,创建
挂钩/add_tools_namespace.js

#!/usr/bin/env node

const fs = require('fs'),
    path = require('path');

module.exports = function (context) {
    const toolsAttribute = "xmlns:tools=\"http://schemas.android.com/tools\"";
    const manifestOpen = "<manifest";

    const manifestPath = path.join(context.opts.projectRoot, 'platforms/android/app/src/main/AndroidManifest.xml');
    let manifest = fs.readFileSync(manifestPath).toString();

    if(manifest.indexOf(toolsAttribute) == -1) {
        manifest = manifest.replace(manifestOpen, manifestOpen + " " + toolsAttribute + " ");
        fs.writeFileSync(manifestPath, manifest, 'utf8');
    }
};