How To Retrieve Path To Adb In Build.gradle
I trying to start application via gradle task. task runDebug(dependsOn: ['installDebug', 'run']) { } task run(type: Exec) { commandLine 'adb', 'shell', 'am', 'start', '-n', 'com
Solution 1:
You should use the logic that the Android Gradle plugin already has for finding the SDK and adb locations to ensure your script is using the same ones.
# 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()
Solution 2:
The problem was solved. The variable must contain
def adb = "$System.env.ANDROID_HOME/platform-tools/adb"
And complete task looks like
task run(type: Exec) {
def adb = "$System.env.ANDROID_HOME/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.example.myexample/.ui.SplashScreenActivity'
}
UPD
Another way without using ANDROID_HOME
task run(type: Exec) {
defrootDir= project.rootDir
deflocalProperties=newFile(rootDir, "local.properties")
if (localProperties.exists()) {
Propertiesproperties=newProperties()
localProperties.withInputStream {
instr -> properties.load(instr)
}
defsdkDir= properties.getProperty('sdk.dir')
defadb="$sdkDir/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.example.myexample/.ui.SplashScreenActivity'
}
}
Solution 3:
defandroidPlugin= project.plugins.findPlugin("android")
defadb= androidPlugin.sdkHandler.sdkInfo?.adb
Solution 4:
In Windows you can just register an application path
for adb.exe
with the following .reg
file:
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\adb.exe]
@="D:\\android\\android-studio\\sdk\\platform-tools\\adb.exe""Path"="D:\\android\\android-studio\\sdk\\platform-tools"
and just keep your original commandline
Solution 5:
My default solution for this issue is to add adb to your path variable so you can use the adb command from every path. You can set it e.g. from the console like this:
set path=%path%;x:\path\to\adb
Alternative you can set it via the UI. See also this explanation on java.com.
Post a Comment for "How To Retrieve Path To Adb In Build.gradle"