C#實現APK自動打包
阿新 • • 發佈:2019-02-05
private void InsertVendorXmlElememnt()
{
List<string> androidnames = new List<string>();
string xmlfile = @"AndroidManifest.xml";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(_androidSourcePath + xmlfile);
XmlNode xmlApp = xmldoc.SelectSingleNode("//application");
XmlNodeList xmlnodes = xmlApp.SelectNodes("//meta-data");
foreach (XmlNode item in xmlnodes)
{
if (!androidnames.Contains(item.Attributes["android:name"].Value))
{
androidnames.Add(item.Attributes["android:name"].Value);
}
}
if (!androidnames.Contains("vendorid"))
{
XmlElement xmlelemember = xmldoc.CreateElement("meta-data");
XmlAttribute memAttr = xmldoc.CreateAttribute("android", "name", "http://schemas.android.com/apk/res/android");
memAttr.Value = "vendorid";
xmlelemember.SetAttributeNode(memAttr);
XmlAttribute memValue = xmldoc.CreateAttribute("android" , "value", "http://schemas.android.com/apk/res/android");
memValue.Value = "";
xmlelemember.SetAttributeNode(memValue);
xmlApp.AppendChild(xmlelemember);
}
xmldoc.Save("d:\src\AndroidManifest.xml");
}
{
List<string> androidnames = new List<string>();
string xmlfile = @"AndroidManifest.xml";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(_androidSourcePath + xmlfile);
XmlNode xmlApp = xmldoc.SelectSingleNode("//application");
XmlNodeList xmlnodes =
foreach (XmlNode item in xmlnodes)
{
if (!androidnames.Contains(item.Attributes["android:name"].Value))
{
androidnames.Add(item.Attributes["android:name"].Value);
}
}
if (!androidnames.Contains("vendorid"))
{
XmlElement xmlelemember =
XmlAttribute memAttr = xmldoc.CreateAttribute("android", "name", "http://schemas.android.com/apk/res/android");
memAttr.Value = "vendorid";
xmlelemember.SetAttributeNode(memAttr);
XmlAttribute memValue = xmldoc.CreateAttribute("android"
memValue.Value = "";
xmlelemember.SetAttributeNode(memValue);
xmlApp.AppendChild(xmlelemember);
}
xmldoc.Save("d:\src\AndroidManifest.xml");
}