我试图通过 gradle
task
启动应用程序。
task runDebug(dependsOn: ['installDebug', 'run']) {
}
task run(type: Exec) {
commandLine 'adb', 'shell', 'am', 'start', '-n', 'com.example.myexample/.ui.SplashScreenActivity'
}
但是这段代码不起作用,我得到错误:
启动进程'command 'adb''时出现问题
但是,当我明确指定 adb 的路径时,应用程序就会启动。
task run(type: Exec) {
commandLine 'D:\\android\\android-studio\\sdk\\platform-tools\\adb', 'shell', 'am', 'start', '-n', 'com.example.myexample/.ui.SplashScreenActivity'
}
那么我怎样才能获得一个包含路径的变量并将其传输到 commandLine
?
最佳答案
您应该使用 Android Gradle 插件已有的逻辑来查找 SDK 和 adb 位置,以确保您的脚本使用相同的位置。
# Android Gradle >= 1.1.0
File sdk = android.getSdkDirectory()
File adb = android.getAdbExe()
# Android Gradle < 1.1.0
File sdk = android.plugin.getSdkFolder()
File adb = android.plugin.extension.getAdbExe()
关于android - 如何在 build.gradle 中检索 ADB 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21288448/