Android Automation compilation Settings Androidmanifest.xml package value (pack name)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.