Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發實例

Android 開發環境常見錯誤與解法整理

編輯:Android 開發實例

工欲善其事,必先利其器。相較於 iOS,Android 的開發環境版本分支更多,踩到的坑自然也更多。與其把寶貴時間耗在環境問題上,不如先有一份清單可查。以下整理最常見的幾類錯誤與處理方式。

Debug certificate expired

Android SDK 產生的除錯憑證 debug.keystore 有效期只有 365 天,超過一年後編譯就會失敗。

Error generating final archive: Debug Certificate expired on 10/09/18 16:30

解法是手動刪除 debug.keystore:Windows 位於 C:\Documents and Settings\username\.android,Linux 與 Mac 位於 ~/.android/。下次啟動時 Eclipse 會自動重建。建議刪完後對專案執行一次「Project → Clean」,強制重新編譯。

Failed to install apk on device: timeout

確切原因不明,一般認為與 adb 連線異常中斷有關。

Failed to install helloworld.apk on device 'emulator-5554': timeout

可嘗試三種做法:

1、換一個 USB 埠(盡量避開機箱前置埠)或重裝手機驅動,並將手機關機重開。
2、在 Eclipse 中開啟「Window → Preferences → Android → DDMS → ADB connection time out」,把預設的 5000ms 調大,例如 20000ms。
3、在命令列依序執行:

adb kill-server
adb start-server

invalid command-line parameter

這是因為 ADT 找不到需要的執行檔,最常見的元兇是 SDK 路徑裡含有空白。

invalid command-line parameter: Files\Android\android-sdk\tools/emulator-arm.exe.

解法:在 Eclipse 開啟「Window → Preferences → Android」,檢查「SDK Location」。若類似 c:\Program Files\android,請改成 8.3 短名稱 c:\Progra~1\android。

小技巧:在命令列輸入 dir /x 就能列出 8.3 格式的短檔名:

2012-09-25  23:52    <DIR>          WATCHD~1  WatchData
2012-09-01  11:01    <DIR>          Winamp
2012-07-24  22:22    <DIR>          WINDOW~4  Windows Live
2012-07-24  22:21    <DIR>          WI3957~1  Windows Live SkyDrive

INSTALL_FAILED_INSUFFICIENT_STORAGE

Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
Please check logcat output for more details. Launch canceled!

若在模擬器上發生,可以擴大 AVD 的內部儲存容量。若在真機上發生,可以在 manifest 中把安裝位置改為優先外部儲存:

<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="com.example"
    android:installLocation="preferExternal" >
    ...
</manifest>

Unable to open sync connection

java.io.IOException: Unable to open sync connection!

成因多種,最直接的兩個處理方式:拔插一次 USB 傳輸線;或到手的機「設定 → 應用程式 → 開發 → USB 除錯」把開關關掉再重新打開。

Too many open files

與系統可同時開啟的檔案數量上限有關,但通常不需要改設定,套用上面「Unable to open sync connection」的手法即可解決。

NoClassDefFoundError(第三方 Jar 包)

升級 ADT 之後,原本正常的專案突然對所有第三方 Jar 包都報 NoClassDefFoundError。原因多半與不同 ADT 版本使用的 ant 編譯腳本差異有關,可試兩個方法:

方法1:右鍵點擊專案 →「Properties → Java Build Path → Order and Export」,把所有第三方 Jar 前面的核選方塊全部勾上。
方法2:確認第三方 Jar 放在專案的「libs」目錄下,不在就移過去。

參考資料

“Debug certificate expired” error in Eclipse Android plugins
Android error: Failed to install *.apk on device *: timeout
The Android emulator is not starting, showing “invalid command-line parameter”
Solution: Android INSTALL_FAILED_INSUFFICIENT_STORAGE error
Android adb “Unable to open sync connection!”
com.android.ddmlib.SyncException: Too many open files
NoClassDefFoundError - Eclipse and Android

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved