poo*_*per 10 android android-manifest cordova cordova-plugins
我正在开发一个Cordova Plugin,我想补充一下
android:allowBackup="true"
Run Code Online (Sandbox Code Playgroud)
进入AndroidManifest.xml,但我不知道如何指定它plugin.xml.
Muh*_*agy 11
对我有用的配置编辑是:
<platform name="android">
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:allowBackup="false"/>
</edit-config>
</platform>
Run Code Online (Sandbox Code Playgroud)
Ven*_*tra 10
为避免 android 应用程序在安装时恢复备份,请在 config.xml 中添加以下配置。
确保定义了 xml 命名空间。如果没有这个,Cordova 构建失败了。
通过添加以下解决。
<platform name="android">
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="false" />
</edit-config>
</platform>
Run Code Online (Sandbox Code Playgroud)
答共享由@Muhammad奥马尔适用于科尔多瓦,机器人<7 。但是对于cordova-android> = 7来说一切都变了
https://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html
因此,您需要对它进行一些更改
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:allowBackup="false"/>
</edit-config>
</platform>
Run Code Online (Sandbox Code Playgroud)
对我有用的配置编辑是:
<platform name="android">
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:allowBackup="false"/>
</edit-config>
</platform>
Run Code Online (Sandbox Code Playgroud)
您必须通过钩子来完成(以下是 Ionic 应用程序的示例):
在你的 config.xml 添加一个钩子:
<platform name="android">
<hook type="before_plugin_install" src="hooks/androidBeforeInstall.js" />
在 hooks 文件夹中创建 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');
};
Run Code Online (Sandbox Code Playgroud)
如果您正在编写需要在应用程序的 AndroidManifest.xml 中添加/编辑某些内容的插件,plugin.xml 中内置了一些功能来执行此操作。对于问题示例,它应该是这样的:
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:allowBackup="true" />
</edit-config>
Run Code Online (Sandbox Code Playgroud)
查看 config-file 和 edit-config 的文档
| 归档时间: |
|
| 查看次数: |
7674 次 |
| 最近记录: |