Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android Studio 升級後卡在「Waiting for device.」的解法

編輯:關於 Android 程式設計

昨天把 Android Studio 升級到 0.8.1,結果 App 竟然跑不起來了。

Run 視窗裡一直停在:

Waiting for device.
Target device: lge-nexus_4-0262fa6d9d51c2e8

而 Event Log 視窗則是:

NoSuchMethodError: com.android.builder.model.AndroidArtifact.getOutputs()Ljava/util/Collection;

折騰了很久都抓不到頭緒。後來想到 Android Studio 是用「解壓覆蓋原目錄」的方式升級的,那麼很可能某個檔案出現了新舊衝突。於是一個一個去比對檔案的時間戳,最後發現只要刪掉 Android Studio 目錄下的這個「舊」檔案,重啟就能恢復:

\android-studio\plugins\android\lib\builder-model-0.11.0.jar

原因在於 Android Studio 0.8.1 使用的 Gradle 已經是 0.12.+ 了,舊版 builder-model 殘留下來自然會與新版 API 對不上,於是拋出 NoSuchMethodError。

根專案的 build.gradle 對應長這樣:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

總結一下這類問題的排查思路:升級 IDE 之後出現莫名的 NoSuchMethodError,先懷疑舊版 jar 是否殘留,比對檔案時間戳往往比盲目重裝更快。

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