github.com/acrespo/mobile@v0.0.0-20190107162257-dc0771356504/cmd/gomobile/install.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 "os/exec" 11 "path/filepath" 12 "strings" 13 ) 14 15 var cmdInstall = &command{ 16 run: runInstall, 17 Name: "install", 18 Usage: "[-target android] [build flags] [package]", 19 Short: "compile android APK and install on device", 20 Long: ` 21 Install compiles and installs the app named by the import path on the 22 attached mobile device. 23 24 Only -target android is supported. The 'adb' tool must be on the PATH. 25 26 The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, and -work are 27 shared with the build command. 28 For documentation, see 'go help build'. 29 `, 30 } 31 32 func runInstall(cmd *command) error { 33 if !strings.HasPrefix(buildTarget, "android") { 34 return fmt.Errorf("install is not supported for -target=%s", buildTarget) 35 } 36 if err := runBuild(cmd); err != nil { 37 return err 38 } 39 40 // Don't use runCmd as adb does not return a useful exit code. 41 c := exec.Command( 42 `adb`, 43 `install`, 44 `-r`, 45 androidPkgName(filepath.Base(pkg.Dir))+`.apk`, 46 ) 47 c.Stdout = os.Stdout 48 c.Stderr = os.Stderr 49 if buildX || buildN { 50 printcmd("%s", strings.Join(c.Args, " ")) 51 } 52 if buildN { 53 return nil 54 } 55 return c.Run() 56 }