Android 系列之Android 命令列手動編譯打包詳解)

來源:互聯網
上載者:User

Android 命令列手動編譯打包過程圖

【詳細步驟】:

 

1使用aapt產生R.java類檔案:
例:
E:\androidDev\android-sdk-windows2.2\tools>E:\androidDev\android-sdk-windows2.2\platforms\android-3\tools\aapt.exe package -f -m -J E:\androidDev\AndroidByread\gen -S res -I E:\androidDev\android-sdk-windows2.2\platforms\android-3\android.jar -M AndroidManifest.xml
其中  -f -m -J E:\androidDev\AndroidByread\gen 代表按覆蓋的形式在gen目錄下產生帶包路徑的R.java,-S res指定資源檔 ,-I E:\androidDev\android-sdk-windows2.2\platforms\android-3\android.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檔案:
例:E:\Androiddev\AndroidByread>javac -encoding GB18030 -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 

4使用android SDK提供的dx.bat命令列指令碼產生classes.dex檔案:

例:
E:\Androiddev\AndroidByread>E:\Androiddev\r\android-sdk-windows2.2\platforms\android-3\tools\dx.bat --dex --output=E:\Androiddev\AndroidByread\bin\classes.dex E:\Androiddev\AndroidByread\bin\classes
其中classes.dex為產生的目標檔案,E:\Androiddev \AndroidByread\bin\classes為class檔案所在目錄

 

5使用Android SDK提供的aapt.exe產生資源套件檔案(包括res、assets、androidmanifest.xml等):
E:\Andorid\AndroidByread>E:\Androiddev\android-sdk-windows2.2\platforms\android-3\tools\aapt.exe package -f -M AndroidManifest.xml -S res -A assets -I E:\Androiddev\android-sdk-windows2.2\platforms\android-3\android.jar -F bin\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} 

例: E:\Adnroiddev\AndroidByread>E:\Adnroiddev\android-sdk- windows2.2\tools\apkbuilder.bat E:\Adnroiddev\byreadreader.apk –v -u -z E:\Adnroiddev\AndroidByread\bin\byreadreader -f E:\Adnroiddev\AndroidByread\bin\class.dex -rf E:\Adnroiddev\AndroidByread\src 其中E:\Adnroiddev\byreadreader.apk為產生的apk ,-z E:\Adnroiddev\AndroidByread\bin\byreadreader為資源套件,E:\Adnroiddev \AndroidByread\bin\class.dex為類檔案包 

 

7使用jdk的jarsigner對未簽名的包進行apk簽名: use jarsigner jarsigner  -keystore ${keystore} -storepass  ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias} 例如: E:\Adnroiddev\android-sdk-windows2.2\tools>jarsigner –keystore E:\Adnroiddev\eclipse3.5\bbyread.keystore -storepass byread002 -keypass byread002 -signedjar E:\Adnroiddev\byread.apk E:\Adnroiddev\byreadreader.apk byread 其中–keystore E:\Adnroiddev\eclipse3.5\bbyread.keystore 為密鑰檔案  -storepass byread002為密鑰檔案密碼 byread 為密鑰別名 -keypass byread002為密鑰別名密碼,-signedjar E:\Adnroiddev\byread.apk為簽名後產生的apk檔案 E:\Adnroiddev\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/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.