http://blog.chinaunix.net/uid-22957718-id-61533.html
ndroid 命令行手动编译打包过程图
【详细步骤】:
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/