Manually modifying the pack value (package name) in Android Androidmanifest.xml is simple and can be modified manually. However, the project needs to put the Android project source code on the server side when the customer download dynamic compilation generated, and the generated app signature is the same but the package name is different (if the package name is the same app), This requirement needs to automatically adjust the package value in Androidmanifest.xml when the server-side Automation compiles the Android source code. Access to relevant data, combined with Java's reading and writing technology for XML files, wrote a method for the server to pre-load and modify the package values in Androidmanifest.xml before compiling.
Parameters://File File:AndroidManifest.xml files. String PackageName: The new package name. public static void Operationandroidmanifestxml (file file, String packagename) {Documentbuilderfactory factory = Documentbuilderfactory.newinstance (); Factory.setignoringelementcontentwhitespace (true);D Ocumentbuilder db;try { db = Factory.newdocumentbuilder ();D ocument doc = db.parse (file); NodeList nl = doc.getchildnodes ();//Only one node, that is, manifest//item (0), is manifest. Node node = nl.item (0);//Get manifest properties NamedNodeMap map = Node.getattributes ();//Reset the package value Map.getnameditem (" Package "). setNodeValue (PackageName);//write SaveXML (file, doc);} catch (Exception e) {e.printstacktrace ();}} Save to XML file private static void SaveXML (file file, Document doc) {transformerfactory transfactory = transformerfactory.new Instance (); try {Transformer Transformer = Transfactory.newtransformer (); Transformer.setoutputproperty ("Indent", " Yes ");D omsource Source = new Domsource (); Source.setnode (DOC); Streamresult result = new Streamresult ();//overwrite the original file ResULt.setoutputstream (new FileOutputStream); Transformer.transform (source, result);} catch (Exception e) {e.printstacktrace ();}}
Android Automation compilation Settings Androidmanifest.xml package value (pack name)