Android 命令行手动编译打包详解
Android 命令行手动编译打包过程图
【详细步骤】:
1使用aapt生成R.java类文件:
例:
F:\explorer\android-sdk-windows2.2\tools>f:\explorer\android-sdk-windows2.2\platforms\android-3\tools\aapt.exepackage-f-m-JF:\explorer\AndroidByread\gen-Sres-If:\explorer\android-sdk-windows2.2\platforms\android-3\android.jar-MAndroidManifest.xml
其中-f-m-JF:\explorer\AndroidByread\gen代表按覆盖的形式在gen目录下生成带包路径的R.java,-Sres指定资源文件,-If:\explorer\android-sdk-windows2.2\platforms\android-3\android.jar指定使用的android类,-MAndroidManifest.xml指定程序的配置文件
aaptUsage:
2使用androidSDK提供的aidl.exe把.aidl转成.java文件:
usage:aidlOPTIONSINPUT[OUTPUT]
aidl--preprocessOUTPUTINPUT...
OPTIONS:
-I<DIR>searchpathforimportstatements.
-d<FILE>generatedependencyfile.
-p<FILE>filecreatedby--preprocesstoimport.
-o<FOLDER>baseoutputfolderforgeneratedfiles.
-bfailwhentryingtocompileaparcelable.
INPUT:
Anaidlinterfacefile.
OUTPUT:
Thegeneratedinterfacefiles.
3第三步编译.java类文件生成class文件:
例:F:\explorer\AndroidByread>javac-encodingGB18030-target1.5-bootclasspathF:\explorer\android-sdk-windows2.2\platforms\android-3\android.jar-dbinsrc\com\byread\reader\*.javagen\com\byread\reader\R.java
4使用androidSDK提供的dx.bat命令行脚本生成classes.dex文件:
例:
F:\explorer\AndroidByread>F:\explorer\android-sdk-windows2.2\platforms\android-3\tools\dx.bat--dex--output=F:\explorer\AndroidByread\bin\classes.dexf:\explorer\AndroidByread\bin\classes
其中classes.dex为生成的目标文件,f:\explorer\AndroidByread\bin\classes为class文件所在目录
5使用AndroidSDK提供的aapt.exe生成资源包文件(包括res、assets、androidmanifest.xml等):
F:\explorer\AndroidByread>F:\explorer\android-sdk-windows2.2\platforms\android-3\tools\aapt.exepackage-f-MAndroidManifest.xml-Sres-Aassets-IF:\explorer\android-sdk-windows2.2\platforms\android-3\android.jar-Fbin\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}
例:
F:\explorer\AndroidByread>f:\explorer\android-sdk-windows2.2\tools\apkbuilder.batf:\explorer\byreadreader.apk–v-u-zf:\explorer\AndroidByread\bin\byreadreader-ff:\explorer\AndroidByread\bin\class.dex-rfF:\explorer\AndroidByread\src
其中f:\explorer\byreadreader.apk为生成的apk,-zf:\explorer\AndroidByread\bin\byreadreader为资源包,f:\explorer\AndroidByread\bin\class.dex为类文件包
7使用jdk的jarsigner对未签名的包进行apk签名:
usejarsigner
jarsigner-keystore${keystore}-storepass${keystore.password}-keypass${keypass}-signedjar${signed.apkfile}${unsigned.apkfile}${keyalias}
例如:
F:\explorer\android-sdk-windows2.2\tools>jarsigner–keystoref:\explorer\eclipse3.5\bbyread.keystore-storepassbyread002-keypassbyread002-signedjarf:\explorer\byread.apkf:\explorer\byreadreader.apkbyread
其中–keystoref:\explorer\eclipse3.5\bbyread.keystore为密钥文件-storepassbyread002为密钥文件密码byread为密钥别名-keypassbyread002为密钥别名密码,-signedjarf:\explorer\byread.apk为签名后生成的apk文件f:\explorer\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/