我現在開發一個Cordova Plugin
allowBackup =「true」時,我想補充如何添加機器人:通過科爾多瓦插件
android:allowBackup="true"
到AndroidManifest.xml
,但我不知道如何在plugin.xml中指定。
我現在開發一個Cordova Plugin
allowBackup =「true」時,我想補充如何添加機器人:通過科爾多瓦插件
android:allowBackup="true"
到AndroidManifest.xml
,但我不知道如何在plugin.xml中指定。
你必須通過掛鉤做到這一點(下面是離子應用爲例):
在你的config.xml中添加一個鉤子爲:
<platform name="android"> <hook type="before_plugin_install" src="hooks/androidBeforeInstall.js" />
在鉤夾創建js文件androidBeforeInstall.js並添加以下代碼:
module.exports = function(ctx) {
var fs = ctx.requireCordovaModule('fs'),
path = ctx.requireCordovaModule('path'),
xml = ctx.requireCordovaModule('cordova-common').xmlHelpers;
var manifestPath = path.join(ctx.opts.projectRoot, 'platforms/android/AndroidManifest.xml');
var doc = xml.parseElementtreeSync(manifestPath);
if (doc.getroot().tag !== 'manifest') {
throw new Error(manifestPath + ' has incorrect root node name (expected "manifest")');
}
doc.getroot().find('./application').attrib['android:allowBackup'] = "true";
//write the manifest file
fs.writeFileSync(manifestPath, doc.write({
indent: 4
}), 'utf-8');
};
這是一個更簡單的例子,但它需要cordova custom config插件。
<platform name="android">
<preference name="android-manifest/application/@android:allowBackup" value="true" />
</platform>`
如果你正在編寫需要添加在應用的AndroidManifest.xml /編輯一些插件,還有內置的plugin.xml做到這一點的功能。它應該是這樣的問題,例如:
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:allowBackup="true" />
</edit-config>
對於PhoneGap的,你可以從config.xml中設置android:allowBackup="false"
:
<config-file platform="android" parent="/manifest">
<application android:allowBackup="false"></application>
</config-file>
相同於:http://stackoverflow.com /問題/ 27550060 /附加androidname出頭到androidmanifest-XML的應用程序標籤從 - cordo – poordeveloper