github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/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/exec"
    10  	"path/filepath"
    11  )
    12  
    13  var cmdInstall = &command{
    14  	run:   runInstall,
    15  	Name:  "install",
    16  	Usage: "[-target android] [build flags] [package]",
    17  	Short: "compile android APK and install on device",
    18  	Long: `
    19  Install compiles and installs the app named by the import path on the
    20  attached mobile device.
    21  
    22  Only -target android is supported. The 'adb' tool must be on the PATH.
    23  
    24  The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, and -work are
    25  shared with the build command.
    26  For documentation, see 'go help build'.
    27  `,
    28  }
    29  
    30  func runInstall(cmd *command) error {
    31  	if buildTarget != "android" {
    32  		return fmt.Errorf("install is not supported for -target=%s", buildTarget)
    33  	}
    34  	if err := runBuild(cmd); err != nil {
    35  		return err
    36  	}
    37  	return runCmd(exec.Command(
    38  		`adb`,
    39  		`install`,
    40  		`-r`,
    41  		filepath.Base(pkg.Dir)+`.apk`,
    42  	))
    43  }