android package.xml,Android自動化編譯設置AndroidManifest.xml中package值(包名)

手動修改Android的AndroidManifest.xml中package值(包名)很簡單,手動修改即可。但是項目中需要把Android的項目源代碼放到服務器端在客戶下載時候動態編譯生成,且生成的app簽名相同但包名不同(若此時包名相同就是相同的app),這種需求需要在服務器端自動化編譯Android源代碼時候自動調整AndroidManifest.xml中package值才能實現。查閱相關資料,結合Java對XML文件的讀寫技術,寫了一個方法,讓服務器端在編譯之前預加載修改AndroidManifest.xml中的package值。

// 參數:

// File file:AndroidManifest.xml文件。

// String packagename:新的包名。

public static void operationAndroidManifestXML(File file, String packagename) {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setIgnoringElementContentWhitespace(true);

DocumentBuilder db;

try {

db = factory.newDocumentBuilder();

Document doc = db.parse(file);

NodeList nl = doc.getChildNodes();

// 只有一個node,即 manifest

// item(0)即為 manifest。

Node node = nl.item(0);

// 獲得manifest的各個屬性

NamedNodeMap map = node.getAttributes();

// 重新設置package的值

map.getNamedItem("package").setNodeValue(packagename);

// 寫

saveXml(file, doc);

} catch (Exception e) {

e.printStackTrace();

}

}

// 保存到XML文件

private static void saveXml(File file, Document doc) {

TransformerFactory transFactory = TransformerFactory.newInstance();

try {

Transformer transformer = transFactory.newTransformer();

transformer.setOutputProperty("indent", "yes");

DOMSource source = new DOMSource();

source.setNode(doc);

StreamResult result = new StreamResult();

// 覆蓋原文件

result.setOutputStream(new FileOutputStream(file));

transformer.transform(source, result);

} catch (Exception e) {

e.printStackTrace();

}

}



本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540833.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540833.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540833.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

css 相同的css屬性_CSS中的order屬性

css 相同的css屬性CSS | 訂單屬性 (CSS | order Property) Introduction: 介紹: Web development is an ever-growing field that would never find its end, therefore it is equally necessary to learn new ways to deal with the elements of the web page or …

StoreServ的ASIC架構師必須面向未來做出決斷

StoreServ陣列采用特殊硬件,即一套ASIC來加速存儲陣列操作,而且其每代陣列都會在這方面進行重新設計。目前的設計為第五代。 作為惠普企業業務公司研究員兼StoreServ架構師,Siamak Nazari當下主要負責第六代ASIC的設計工作。 每代ASIC設計往往…

android網頁省略分頁器,Android輕量級網頁風格分頁器

博客同步自:個人博客主頁輕量級仿網頁風格分頁器,和RecycleView封裝一起配合使用,也可單獨使用,喜歡就star、fork下吧~謝謝目錄功能介紹效果圖如何引入簡單使用依賴github地址功能介紹支持延遲加載分頁支持單獨分頁器組件使用&…

scala重載無參構造方法_Scala中的無參數方法

scala重載無參構造方法Scala無參數方法 (Scala parameterless method) A method which accepts no parameters from the calling code. It also denotes that there will not be any empty parentheses. These are special types of methods in Scala that are initialized and…

傳統存儲做到極致也驚人!看宏杉科技發布的CloudSAN

傳統存儲陣列首先考慮的是高可靠、高性能。那么在成本上、擴展上、部署上就差。 互聯網企業帶來分布式存儲,擴展上、部署上是優勢了,但是單節點的可靠性差、數據一致性差、IO延遲大、空間浪費嚴重,能耗大。 這兩者的問題,我想很多…

android inflate,Android 關于inflate

通俗的說,inflate就相當于將一個xml中定義的布局找出來.因為在一個Activity里如果直接用findViewById()的話,對應的是setConentView()的那個layout里的組件.因此如果你的Activity里如果用到別的layout,比如對話框上的layout,你還要設置對話框上的layout里的組件(像圖片ImageVie…

keil lic_LIC的完整形式是什么?

keil licLIC:印度人壽保險公司 (LIC: Life Insurance Corporation of India) LIC is an abbreviation of the Life Insurance Corporation of India. It is a public segment insurance and investment group corporation in India that generally deals with life …

“云”上存儲初顯規模 如何架構是關鍵

在安防系統中,存儲設備只是給數據提供存儲空間,數據存儲的意義更多是為了給上層應用提供二次挖掘。目前的智能分析、大數據、圖幀等技術都是基于數據存儲做的數據挖掘。為了將二次挖掘應用的性能提升到最高,在優化分析算法的同時,…

在線圖片轉成html,在線將JPEG 轉換成HTML。 免費將.jpeg 轉換成.html。

描述|介紹JPEG – is a popular graphic format, which is characterized by a high degree of compression, which leads to a decrease in image quality. It uses the technology of encoding of smooth color renditions, providing the ability to reduce the amount of d…

密碼學常用的算法填充模式_密碼學的操作模式

密碼學常用的算法填充模式Modes of operation of a block cipher are procedural rules for a generic block cipher. The different modes of operation result in different properties being achieved which add to the security of the underlying block cipher in the cry…

【干貨】分享總結:MySQL數據一致性

0、導讀 沃趣科技數據庫工程師羅小波為大家全面分析如何保證MySQL的數據一致性。 1、活動總結 羅小波老師從MySQL的崩潰數據恢復安全性、MySQL復制原理及異步&semi sync復制原理、MySQL主從服務器如何保證數據一致性等多方面分析如何保證MySQL的數據一致性。 分享內容滿滿的…

設置html按鈕點擊事件無效果,css怎么設置按鈕不能點擊?

css怎么設置按鈕不能點擊?下面本篇文章就來給大家介紹一下使用CSS設置按鈕不能點擊的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。想要按鈕不能點擊可以通過設置按鈕點擊事件失效來實現;而在CSS中&…

計算機圖形學與幾何造型導論_計算機圖形學導論

計算機圖形學與幾何造型導論歷史 (History) The main forerunner sciences to the development of modern computer graphics were the advances in electrical engineering, electronics, and television that took place during the first half of the twentieth century whe…

android scrollview焦點,scrollview里面的edittext,當它獲得焦點時如何滾動到edittext

在scrollview中有一個edittext。 (并且edittext上方的scrollview中還有其他視圖。)當用戶按下edittext時,鍵盤變得可見,并且scrollview的可見區域變得很小。因為edittext沒有顯示在屏幕上。 (它不會滾動滾動視圖,以便顯示編輯文本。)在用戶按…

Linux中解壓rar文件

Linux平臺默認是不支持RAR文件的解壓,需要安裝linux版本的RAR壓縮軟件,下載地址為:http://www.rarlab.com/download.htm 下載之后進行解壓之后,進入rar目錄,運行make指令進行安裝: [rootlocalhost rar]# ls…

kotlin 查找id_Kotlin程序查找立方體區域

kotlin 查找idA cube has 6 square faces, if edges length is side. Then the area of each square is side2, thus, the area of cube will be 6*sise2. 如果邊的長度為side ,則一個立方體有6個正方形的面。 那么每個正方形的面積是邊2 ,因此&#xff…

Python自動化運維之高級函數

一、協程1.1協程的概念協程,又稱微線程,纖程。英文名Coroutine。一句話說明什么是線程:協程是一種用戶態的輕量級線程。(其實并沒有說明白~)那么這么來理解協程比較容易:   線程是系統級別的,…

android 繼承listview,Android listView 繼承ListActivity的用法

Android listView 繼承ListActivity的用法 在手機中經常有列表方式。如果Activity中只有唯??個List(這也是通常的情況),可以繼承ListActivity來實現。我們用兩個例子來學習List。List例子?:利用Android自帶的List格式步驟?:Android XML文…

計算機圖形學的應用

Some of the applications of computer graphics are, 計算機圖形學的一些應用是 Education and Training 教育和培訓 Use in Biology 用于生物學 Computer-Generated Maps 計算機生成的地圖 Architect 建筑師 Presentation Graphics 演示圖形 Computer Art 電腦美術 Entertai…

html頁面授權碼,spring boot 2.0 整合 oauth2 authorization code授權碼模式

oauth2 authorization code 大致流程用戶打開客戶端后,客戶端要求用戶給予授權。用戶同意給予客戶端授權。客戶端使用授權得到的code,向認證服務器申請token令牌。認證服務器對客戶端進行認證以后,確認無誤,同意發放令牌。客戶端請…