Android 命令列手動編譯打包過程圖
【詳細步驟】:
1使用aapt產生R.java類檔案:
例:
E:\androidDev\android-sdk-windows2.2\tools>E:\androidDev\android-sdk-windows2.2\platforms\android-3\tools\aapt.exe package -f -m -J E:\androidDev\AndroidByread\gen -S res -I E:\androidDev\android-sdk-windows2.2\platforms\android-3\android.jar -M AndroidManifest.xml
其中 -f -m -J E:\androidDev\AndroidByread\gen 代表按覆蓋的形式在gen目錄下產生帶包路徑的R.java,-S res指定資源檔 ,-I E:\androidDev\android-sdk-windows2.2\platforms\android-3\android.jar 指定使用的android類,-M AndroidManifest.xml指定程式的設定檔
aapt Usage:
2使用android SDK提供的aidl.exe把.aidl轉成.java檔案:
usage: aidl OPTIONS INPUT [OUTPUT]
aidl --preprocess OUTPUT INPUT...
OPTIONS:
-I<DIR> search path for import statements.
-d<FILE> generate dependency file.
-p<FILE> file created by --preprocess to import.
-o<FOLDER> base output folder for generated files.
-b fail when trying to compile a parcelable.
INPUT:
An aidl interface file.
OUTPUT:
The generated interface files.
3第三步 編譯.java類檔案產生class檔案:
例:E:\Androiddev\AndroidByread>javac -encoding GB18030 -target 1.5 -bootclasspath E:\Androiddev\android-sdk-windows2.2\platforms\android-3\android.jar -d bin src\com\byread\reader\*.java gen\com\byread\reader\R.java
4使用android SDK提供的dx.bat命令列指令碼產生classes.dex檔案:
例:
E:\Androiddev\AndroidByread>E:\Androiddev\r\android-sdk-windows2.2\platforms\android-3\tools\dx.bat --dex --output=E:\Androiddev\AndroidByread\bin\classes.dex E:\Androiddev\AndroidByread\bin\classes
其中classes.dex為產生的目標檔案,E:\Androiddev \AndroidByread\bin\classes為class檔案所在目錄
5使用Android SDK提供的aapt.exe產生資源套件檔案(包括res、assets、androidmanifest.xml等):
E:\Andorid\AndroidByread>E:\Androiddev\android-sdk-windows2.2\platforms\android-3\tools\aapt.exe package -f -M AndroidManifest.xml -S res -A assets -I E:\Androiddev\android-sdk-windows2.2\platforms\android-3\android.jar -F bin\byreadreader
將AndroidManifest.xml,res和assets檔案夾中的資源檔打包產生 byreadreader,用法參見1
6第六步 產生未簽名的apk安裝檔案:
apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file} -rf ${source.dir} -rj ${libraries.dir}
例: E:\Adnroiddev\AndroidByread>E:\Adnroiddev\android-sdk- windows2.2\tools\apkbuilder.bat E:\Adnroiddev\byreadreader.apk –v -u -z E:\Adnroiddev\AndroidByread\bin\byreadreader -f E:\Adnroiddev\AndroidByread\bin\class.dex -rf E:\Adnroiddev\AndroidByread\src 其中E:\Adnroiddev\byreadreader.apk為產生的apk ,-z E:\Adnroiddev\AndroidByread\bin\byreadreader為資源套件,E:\Adnroiddev \AndroidByread\bin\class.dex為類檔案包
7使用jdk的jarsigner對未簽名的包進行apk簽名: use jarsigner jarsigner -keystore ${keystore} -storepass ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias} 例如: E:\Adnroiddev\android-sdk-windows2.2\tools>jarsigner –keystore E:\Adnroiddev\eclipse3.5\bbyread.keystore -storepass byread002 -keypass byread002 -signedjar E:\Adnroiddev\byread.apk E:\Adnroiddev\byreadreader.apk byread 其中–keystore E:\Adnroiddev\eclipse3.5\bbyread.keystore 為密鑰檔案 -storepass byread002為密鑰檔案密碼 byread 為密鑰別名 -keypass byread002為密鑰別名密碼,-signedjar E:\Adnroiddev\byread.apk為簽名後產生的apk檔案 E:\Adnroiddev\byreadreader.apk為未簽名的檔案。
參 考:http://asantoso.wordpress.com/2009/09/15/how-to-build-android- application-package-apk-from-the-command-line-using-the-sdk-tools-continuously-integrated-using-cruisecontrol/