標籤:android blog http io ar os 使用 sp for
記不住,於是原帖轉過來,請看原帖:http://blog.csdn.net/ms03001620/article/details/8490238
一、產生build.xml
Eclipse中使用Ant為Android打包並且簽名
SDK內建檔案 在<sdk>tools/ant目錄下這3個檔案
其中build.xml和uibuild.xml中定義了大量基礎構建方法和打包策略。我們只需要建立我們自己的build.xml並且存放在項目的根目錄下,然後引用一下<sdk>tools/ant/build.xml即可。當然也可以拷貝它然後直接操作。
那麼如何。以項目AntForAndroid為例。產生一個針對該項目的build.xml呢?
這裡需要一個工具。就是SDK內建的android.bat .所在目錄<sdk>tools/android.bat
然後通過命令列執行“android update project --path .”即可。完畢後即可通過android命令在當前項目目錄下產生一個build.xml檔案
新產生的3個檔案 build.xml,local.properties,proguard-project.exe
二、配置ant.properties
在項目根目錄建立一個ant.properties檔案(不要去改變他的名字,因為<sdk>\tools\ant\build.xml會引用到這個名字)
並且在裡面寫入一下資料:
#keystore檔案的目錄,因為在根目錄下所以直接寫名字了
key.store=android.keystore
#這個名字就是在產生keystore時那個alias欄位的值
key.alias=android
#兩個密碼分別寫建立keystore時的兩個密碼
key.store.password=(your pwd)
key.alias.password=(your pwd)
三、實現自動打簽名apk
右鍵點擊項目中的build.xml->run as... 先查看下有多少種任務,當然這些任務都是來自<sdk>\tools\ant\build.xml,項目裡的只是引用了它
視窗開啟
預設的選擇在help上。打簽名包的時候執行release這個任務即可。
按照以上的步驟配置好之後就能產生簽名apk。並且大家可以通過學習<sdk>\tools\ant\build.xml來理解ant的基本奧妙。
最後在項目跟目錄\bin下產生apk包
Ant是非常強大的。可以實現一下功能
例如
1.在產生apk的檔案名稱裡加上日期。
2.把apk檔案自動通過郵件發給其他人。
3.apk檔案上傳伺服器
等等
第二篇:http://www.xmumu.com/post/2011-11-22/7022215
通過Android命令自動編譯出build.xml檔案
用途: 做自動整合編譯環境.
環境搭配我就不說了(SDK/環境變數等).
進入cmd介面.
進入項目目錄.
輸入: android.bat list target 來查詢我們現有的版本list有哪些.
記住這個ID號碼,下的代碼面會用到.
輸入: android update project -n ButtonDemo -t 1 -p E:\workspace\android\ButtonDemo
-n 對應的是項目名稱
-t 就是我們之前查詢的SDK版本對應的ID,大家根據自己的項目版本做出選擇即可,我這個是android-8 所以用ID 1 .
-p就是產生的路徑
成功後顯示:
好了以下是產生的build.xml程式碼片段:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ButtonDemo" default="help">
<!-- The local.properties file is created and updated by the ‘android‘ tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<loadproperties srcFile="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
‘android‘ tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is ‘src‘.
out.dir
The name of the output directory. Default is ‘bin‘.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the ‘android‘ tool with the ‘update‘ action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the ‘android‘
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using ‘android update project‘"
unless="sdk.dir"
/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
<target name="-post-compile">
</target>
-->
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read ‘custom‘ instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
【轉】Android項目使用Ant打包,產生build.xml