问题描述
我决定开启新问题,因为没有已经发布的问题,有一个很好的答案。
我需要更新AndroidManifest.xml plugin.xml,以便<应用程序>标签具有以下属性以及它已经具有的属性:
android:name =mypackage
如何做?
谢谢
解决方案我有同样的问题,我使用Cordova钩子做这项工作。
首先,编辑您的
config.xml
文件以添加挂钩:< platform name =android>
< hook type =after_preparesrc =scripts / android_app_name.js/>
< / platform>
创建一个名为
scripts / android_app_name.js
(设置它可执行),并在里面,只需使用搜索/替换功能。它应该像:#!/ 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 ){
throw new Error('Unable to find AndroidManifest.xml:'+ err);
}
var appClass ='YOU_APP_CLASS';
$ b b 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('无法写入AndroidManifest.xml :'+ err);
})
}
});
}
};
I decided to open new question because none of those that are already posted, has a good answer.
I need to update AndroidManifest.xml "from plugin.xml", so that the < application> tag has the following property, alongside those it already has:
android:name="mypackage"
How can do that?
Thank you
解决方案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); }) } }); } };
这篇关于添加android:name =" something"到AndroidManifest.xml“应用程序”标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!