-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.go
43 lines (39 loc) · 904 Bytes
/
paths.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
)
func defaultSdkFolder() string {
home, _ := os.UserHomeDir()
switch runtime.GOOS {
case "darwin":
return filepath.Join(home, "Library", "Android", "sdk")
case "windows":
return filepath.Join(home, "AppData", "Local", "Android", "Sdk")
case "linux":
return filepath.Join(home, "Android", "Sdk")
default:
return ""
}
}
func findADB() (string, error) {
// Look for adb in PATH
path, err := exec.LookPath("adb")
if err == nil {
return path, nil
}
// Look for adb in default Android Studio location
switch runtime.GOOS {
case "windows":
path = filepath.Join(defaultSdkFolder(), "platform-tools", "adb.exe")
default:
path = filepath.Join(defaultSdkFolder(), "platform-tools", "adb")
}
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
return "", os.ErrNotExist
}
return path, nil
}