`
JasonShieh
  • 浏览: 520953 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

用命令行编译APK(英文版)

 
阅读更多
How to build Android application package (.apk) from the command line using the SDK tools
Hello all android developers, I just want to share my experience building android apk manually using sdk tools without using Eclipse.  My original goal is motivated firstly by the desire to incorporate continuous integration aspect to Android development process and secondly to ditch the ADT eclipse plugin since the plugin auto-build process blocks Eclipse UI if you have large resources, assets in your Android project,  and a slow computer like mine.  I am using CruiseControl as my continuous integration tool.

Below is one of the many apk build processes:



Build process

The good thing about building manually your apk is that you don’t have to name your resources directory to res, you can name it anything you want.

You can find ant scripts in: <SDK_HOME>\platforms\android-1.5\templates\android-rules.xml

Step 1: Generate Resource java code and packaged Resources
aapt  package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library} -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]
Step 2: Compile java source codes + R.java
use javac

Step 3: Convert classes to Dalvik bytecodes
use dx.bat
dx.bat  –dex  –output=${output.dex.file}  ${compiled.classes.directory}  ${jar files..}

Step 4: Create unsigned APK
use apkbuilder

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

or

apkbuilder  ${output.apk.file} -u -z  ${packagedresource.file} -f  ${dex.file}  -rf  ${source.dir}  -rj  ${libraries.dir}

-rf = resources required for compiled source files?
-rj = resources required for jar files

Step 6: Generate a key
use keytool

Step 7: Sign APK
use jarsigner

jarsigner  -keystore ${keystore} -storepass  ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias}

Step 8: Publish
use adb
adb -d install -r ${signed.apk}

Inspecting your APK file:

aapt list -v latest.apk

Open questions:
1. Can you include more than one dex file in the apk?
2. Can you have dex file named other than classes.dex in the apk?
3. Does an apk have to have a packaged resource?

Note: If upon installing your app using adb you see this error code FAILED_INSTALL_DEXOPT then most likely that either you don’t have classes.dex or you don’t have a packaged resource in the apk
分享到:
评论

相关推荐

    Android Apk命令行编译签名打包大全

    这里详细的介绍了如何使用命令编译apk 签名 打包,很实用,如果你是Android开发者一定要知道如何编译签名apk

    一键反编译apk工具

    android一键反编译apk工具 bat命令行脚本

    反编译apk文件工具及使用方法

    反编译Apk得到Java源代码 转载自:http://hi.baidu.com/%CB%BF%D4%B5%CC%EC%CF%C2/blog/item/2284e2debafc541e495403ec.html 工具下载:需用到dex2jar和JD-GUI这2个工具 dex2jar下载地址:...

    反编译Apk(包括apktool、dex2jar和JD-GUI)下载

    一、反编译Apk得到Java源代码 首先要使用到下载的这两个工具:dex2jar和JD-GUI,前者是将apk中的classes.dex转化成Jar文件,而JD-GUI是一个反编译工 具,可以直接查看Jar包的源代码。 具体步骤: 首先将apk文件,将...

    apk反编译图形界面工具(远离命令行)

    apk反编译图形界面工具,无需命令行下操作

    ApkTool 1.5.1 反编译apk工具

    可用于反编译apk文件以及可以重新编译打包。该版本为1.5.1。 用法:(先命令行cd到apktool.bat目录下) 1、反编译:apktool d xxx.apk xxx 2、重新编译:apktool b xxx 3、重新编译后的apk见于xxx文件夹下的dist目录

    反编译APK,dex2jar和JD-GUI

    一、反编译Apk得到Java源代码 首先要使用到下载的这两个工具:dex2jar和JD-GUI,前者是将apk中的classes.dex转化成Jar文件,而JD-GUI是一个反编译工 具,可以直接查看Jar包的源代码。 具体步骤: 首先将apk文件,将...

    反编译apk文件(android)

    该工具可以将apk文件反编译成java源代码。 使用方法: 1.提取apk中的class.dex文件: 比如有apk文件:qq.apk,将其改名为qq.zip,然后解压,可以看到classes.dex。 2.解压"apk反编译工具.zip": 解压后,将classes....

    将apk文件反编译成java源码

    把.apk文件改名为.zip,然后解压缩,得到其中的classes.dex文件,它就是java文件编译再通过dx工具打包成的,所以现在我们就用上述提到的2个工具来逆方向导出java源文件 2.把classes.dex拷贝到dex2jar.bat所在目录。 ...

    反编译apk为java代码的工具

    反编译apk得到其源代码。方法如下 1.首先找到Android软件安装包中的classes.dex 把apk文件改名为.zip,然后解压缩其中的classes.dex文件,它就是java文件编译再通过dx工具打包成的,所以现在我们就用上述提到的2个...

    mac或linux下反编译apk的工具脚本

    依赖dex2jar工具的反编译脚本文件,能够实现一步反编译的目的,非常方面,只要执行一个命令行就可生成目标jar。

    APK反编译图形化工具

    这是一款很方便的apk反编译工具,图形化的操作方式省去了命令行的敲击。

    apk2java反编译工具最全版

    apk2java : 命令行反编译工具 dex2jar-0.0.9.9 : 新版本 dex2jar-0.0.7 : 老版本 =================================================================== 对有些反编译不成功的apk,请更新最新的apktool.jar、 ...

    安卓apk文件完美反编译

    一、apk反编译得到程序的源代码、图片、XML配置、语言资源等文件 下载上述工具中的apktool,解压得到3个文件:aapt.exe,apktool.bat,apktool.jar ,将需要反编译的APK文件放到该目录下, 打开命令行界面(运行-CMD...

    Android反编译工具 APK反编译工具

    首先将apk文件后缀改为zip并解压 得到其中的classes dex 它就是java文件编译再通过dx工具打包而成的 将classes dex复制到dex2jar bat所在目录 dex2jar 0 0 9 9文件夹 在命令行下定位到dex2jar bat所在目录 运行 dex...

    安卓手机APK反编译工具

    一、反编译Apk得到Java源代码 首先要使用到下载的这两个工具:dex2jar和JD-GUI,前者是将apk中的classes.dex转化成Jar文件,而JD-GUI是一个反编译工 具,可以直接查看Jar包的源代码。 具体步骤: 首先将apk文件,将...

    Android APK反编译工具包(全)

    上述步骤一、二讲述了命令行反编译apk,现在提供一种图形化反编译工具:Androidfby 首先,下载上述反编译工具包,打开Androidfby目录,双击Android反编译工具.exe,就可以浏览打开要反编译的apk

    apk 文件反编译工具

    超好用的傻瓜式apk反编译工具,直接在命令行输入 命令:parseAPK.bat file1.apk 如:命令:parseAPK.bat D:\folder\file.apk D:\folder\file2.apk 即可

    apk反编译,打包及签名工具(附详细使用说明)

    1) APKtool软件包 及...这个命令行是使用test证书的例子:java -jar signapk.jar testkey.x509.pem testkey.pk8 YOURAPK.apk YOURAPK_signed.apk YOURAPK_signed.apk就是签完名的apk,去测试一下您重新打包的apk吧。

Global site tag (gtag.js) - Google Analytics