[android]android自動化測試六之命令列編譯APK

大搜車-自娛發表於2012-02-13
手動編譯你的apk,可以讓資源目錄不命名為res, 你能夠命名任何你想要的名字。

你可以在以下目錄發現ant指令碼: <SDK_HOME>/platforms/android-1.5/templates/android-rules.xml

第一步: 產生R檔案以及包資源
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}]


第二步:編譯java原始檔以及R.java檔案
use javac


第三步:將classes檔案轉化成Dalvik自節碼
use dx.bat
dx.bat –dex –output=${output.dex.file} ${compiled.classes.directory} ${jar files..}

第四步:建立未簽名的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

第六步: 產生一個key
use keytool

第七步驟: 對APK進行簽名
use jarsigner

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


第八步: 釋出
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?

相關文章