協助測試 Android APP,遇到一些狀況,把排解流程記錄一下。

 

 

【ADB server 發生錯誤】

eclipse 會出現錯誤訊息:

[2017-08-16 14:41:39 - MyApp] ------------------------------
[2017-08-16 14:41:39 - MyApp] Android Launch!
[2017-08-16 14:41:39 - MyApp] The connection to adb is down, and a severe error has occured.
[2017-08-16 14:41:39 - MyApp] You must restart adb and Eclipse.
[2017-08-16 14:41:39 - MyApp] Please ensure that adb is correctly located at '/Applications/sdk/platform-tools/adb' and can be executed.
 

在 stackoverfolw 的 “The connection to adb is down, and a severe error has occured.” 這篇提到:

  1. 關閉執行中的 Eclipse
  2. 在命令列切換到 SDK platform-tools 目錄下
  3. 輸入 adb kill-server
  4. 輸入 adb start-server
  5. 等到 ADB server 重啟成功後,再重新啟動 Eclipse。

 

不過要執行時會顯示不認識 adb 這個指令的錯誤訊息:

  • -bash: adb: command not found

這時要先在環境變數裡設定 PATH,在命令列 (terminal) 執行以下指令(目錄路徑依實際安裝而定):

  • export PATH=/Applications/sdk/platform-tools/:$PATH

 

 

【將 Log 寫到 Logcat 進行除錯】

為了要將 Log 寫出來印到 Eclipse 的 Logcat 視窗裡,要先 import log 相關的 class:

import android.util.Log;

然後在程式裡就可以用這樣的格式寫 Log:

Log.v("tag name", "message or information");

Log 有五種格式:

  • Log.v(TAG,Message): Verbose 記錄詳細訊息 
  • Log.d(TAG,Message): Debug 除錯 
  • Log.i(TAG,Message): INFO 資訊 
  • Log.w(TAG,Message): Warning 警告 
  • Log.e(TAG,Message): Error 錯誤

在 Logcat 裡會分色顯示,可以依照實際的需要來分類。下好 tag 也有助於篩選落落長的 Log。(系統自己預設也會印出一些 Log)

arrow
arrow
    全站熱搜

    小攻城師 發表在 痞客邦 留言(0) 人氣()