引用:http://jojol-zhou.iteye.com/blog/729254
Android 命令行手动编译打包过程图
【详细步骤】:
1使用aapt生成R.java类文件:
例:
F:explorerandroid-sdk-windows2.2 ools>f:explorerandroid-sdk-windows2.2platformsandroid-3 oolsaapt.exe package -f -m -J F:explorerAndroidByreadgen -S res -I f:explorerandroid-sdk-windows2.2platformsandroid-3android.jar -M AndroidManifest.xml
其中 -f -m -J F:explorerAndroidByreadgen 代表按覆盖的形式在gen目录下生成带包路径的R.java,-S res指定资源文件 ,-I f:explorerandroid-sdk-windows2.2platformsandroid-3android.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文件:
例:F:explorerAndroidByread>javac -encoding GB18030 -target 1.5 -bootclasspath F:explorerandroid-sdk-windows2.2platformsandroid-3android.jar -d bin srccomyread
eader*.java gencomyread
eaderR.java
4使用android SDK提供的dx.bat命令行脚本生成classes.dex文件:
例:
F:explorerAndroidByread>F:explorerandroid-sdk-windows2.2platformsandroid-3 oolsdx.bat --dex --output=F:explorerAndroidByreadinclasses.dex f:explorerAndroidByreadinclasses
其中classes.dex为生成的目标文件,f:explorerAndroidByreadinclasses为class文件所在目录
5使用Android SDK提供的aapt.exe生成资源包文件(包括res、assets、androidmanifest.xml等):
F:explorerAndroidByread>F:explorerandroid-sdk-windows2.2platformsandroid-3 oolsaapt.exe package -f -M AndroidManifest.xml -S res -A assets -I F:explorerandroid-sdk-windows2.2platformsandroid-3android.jar -F binyreadreader
将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}
例:
F:explorerAndroidByread>f:explorerandroid-sdk-windows2.2 oolsapkbuilder.bat f:exploreryreadreader.apk –v -u -z f:explorerAndroidByreadinyreadreader -f f:explorerAndroidByreadinclass.dex -rf F:explorerAndroidByreadsrc
其中f:exploreryreadreader.apk为生成的apk ,-z f:explorerAndroidByreadinyreadreader为资源包,f:explorerAndroidByreadinclass.dex为类文件包
7使用jdk的jarsigner对未签名的包进行apk签名:
use jarsigner
jarsigner -keystore ${keystore} -storepass ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias}
例如:
F:explorerandroid-sdk-windows2.2 ools>jarsigner –keystore f:explorereclipse3.5byread.keystore -storepass byread002 -keypass byread002 -signedjar f:exploreryread.apk f:exploreryreadreader.apk byread
其中–keystore f:explorereclipse3.5byread.keystore 为密钥文件 -storepass byread002为密钥文件密码 byread 为密钥别名 -keypass byread002为密钥别名密码,-signedjar f:exploreryread.apk为签名后生成的apk文件 f:exploreryreadreader.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/