Android Apk 编译过程

本文详细介绍了Android应用从源代码到APK的编译过程,包括javac编译源码、转换为Dex文件、使用apkbuilder打包、jarsigner签名以及zipalign对齐处理的步骤。此外,还提到了自动化构建的可能性。
摘要由CSDN通过智能技术生成
  1. -d <目录>                    指定存放生成的类文件的位置

  2. -s <目录>                    指定存放生成的源文件的位置

  3. -implicit:{none,class}     指定是否为隐式引用文件生成类文件

  4. -encoding <编码>             指定源文件使用的字符编码

  5. -source <版本>               提供与指定版本的源兼容性

  6. -target <版本>               生成特定 VM 版本的类文件

  7. -version                   版本信息

  8. -help                      输出标准选项的提要

  9. -Akey[=value]              传递给注释处理程序的选项

  10. -X                         输出非标准选项的提要

  11. -J<标志>                     直接将 <标志> 传递给运行时系统

例子:

javac -encoding utf-8 -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

第四步:把.class文件转化成Davik VM支持的.dex文件

将工程bin目录下的class文件编译成classes.dex,Android虚拟机只能执行dex文件!

例子:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

第五步:打包生成未签名的.apk文件

【输入】打包后的资源文件、打包后类文件(.dex文件)、libs文件(包括.so文件,当然很多工程都没有这样的文件,如果你不使用C/C++开发的话)

【输出】未签名的.apk文件

【工具】apkbuilder工具

apkbuilder工具用法如下:

  1. -v      Verbose.

  2. -d      Debug Mode: Includes debug files in the APK file.

  3. -u      Creates an unsigned package.

  4. -storetype Forces the KeyStore type. If ommited the default is used.

  5. -z      Followed by the path to a zip archive.

  6. Adds the content of the application package.

  7. -f      Followed by the path to a file.

  8. Adds the file to the application package.

  9. -rf     Followed by the path to a source folder.

  10. Adds the java resources found in that folder to the application

  11. package, while keeping their path relative to the source folder.

  12. -rj     Followed by the path to a jar file or a folder containing

  13. jar files.

  14. Adds the java resources found in the jar file(s) to the application

  15. package.

  16. -nf     Followed by the root folder containing native libraries to

  17. include in the application package.

列子:

apkbuilder  {output.apk.file} -u -z  {output.apk.file} -u -z  {output.apk.file} -u -z  {packagedresource.file} -f  {dex.file}  -rf  {dex.file}  -rf 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值