Gradle 2.14
android {
dev {
}
}
task runAppDev(type: Exec, dependsOn: 'installDev') {
description "Install and run app (dev env)"
android.applicationVariants.all { variant ->
if ("installDev".toUpperCase().endsWith(variant.getName().toUpperCase())) {
commandLine getRunAppCommandLine(variant)
}
}
}
def getRunAppCommandLine(variant) {
List<String> commandLine = ["adb", "shell", "am", "start", "-n", variant.getApplicationId() + "/.activity.SplashActivity"]
return commandLine
}
通过以下方式运行我的任务:gradlew runAppDev
结果:
在“Nexus 5 - 6.0.1”上为 app:dev 安装 APK“app-dev.apk” 安装在 1 台设备上。 :应用程序:运行AppDev 构建成功
因此,我的应用程序成功安装在设备上,但未在设备上运行。
最佳答案
我发现了错误。我发送了不正确的 adb arg。此处修复:
def getRunAppCommandLine(variant) {
List<String> commandLine = ["adb", "shell", "monkey", "-p", variant.getApplicationId() + " 1"]
return commandLine
}
关于android - 如何通过 gradle 任务在设备上安装和运行 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41879940/