1

接続された Android デバイスのアプリ/データ キャッシュをクリアする adb コマンドを実行する Gradle タスクを作成しようとしています。

task clearAppDataCache(type: Exec) {
    description = "Clears device app data/cache."
    group = "Utils"

    commandLine "$sdkDir/platform-tools/adb"
    args = ["shell", "pm", "clear", "com.my.package"]
}

上記のタスクは、com.my.package android パッケージがデバイスにインストールされている場合に機能します。ただし、パッケージがインストールされていない場合、タスクは失敗を出力し、次のようにハングします。

シェルのスクリーンショット

なぜこれが当てはまるのか誰にもわかりますか?代わりに、生のシェルコマンドの実行方法と同様の方法で失敗して終了することを期待しています。

編集:

次の構成句をタスクに追加すると、ハングが停止します。

doFirst {
        if (!packageExists("com.my.package"))
            throw new GradleException("com.my.package package is not installed on connected device.")
    }

次の関数定義を使用します。

/**
  * Returns true if the packageName argument exists on the the connected device,
  * false otherwise.
  */
def packageExists(String packageName) {
    def output = "adb shell pm list packages -f".execute().waitFor().text
    if (output.contains("$packageName")) return true
    return false
}

ただし、そもそもハングする理由をまだ探しています。

4

1 に答える 1

0

Try this:

task clearAppDataCache(type: Exec) {
    description = "Clears device app data/cache."
    group = "Utils"
    commandLine "./pmclear.sh"
}

pmclear.sh:

#!/bin/bash
[ "`adb shell "pm list packages com.my.package"`" == "" ] || adb shell "pm clear com.my.package
于 2013-08-21T21:08:30.193 に答える