2
0
mirror of synced 2025-02-24 15:28:28 +00:00
mobile/cmd/gomobile/install.go
Hyang-Ah (Hana) Kim b39ed682d8 cmd/gomobile: sanitize android app package names
https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

"This can occur if the domain name contains a hyphen or other special
character, if the package name begins with a digit or other character
that is illegal to use as the beginning of a Java name, or if the
package name contains a reserved Java keyword, such as "int". In this
event, the suggested convention is to add an underscore."

The sanitized name is used for the app package name and the default apk
file name.

Update golang/go#12273

Change-Id: I76d7f423e87c54a5bb7ab71ec251fd3a26da9722
Reviewed-on: https://go-review.googlesource.com/16875
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-11-18 17:26:55 +00:00

57 lines
1.2 KiB
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
var cmdInstall = &command{
run: runInstall,
Name: "install",
Usage: "[-target android] [build flags] [package]",
Short: "compile android APK and install on device",
Long: `
Install compiles and installs the app named by the import path on the
attached mobile device.
Only -target android is supported. The 'adb' tool must be on the PATH.
The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, and -work are
shared with the build command.
For documentation, see 'go help build'.
`,
}
func runInstall(cmd *command) error {
if buildTarget != "android" {
return fmt.Errorf("install is not supported for -target=%s", buildTarget)
}
if err := runBuild(cmd); err != nil {
return err
}
// Don't use runCmd as adb does not return a useful exit code.
c := exec.Command(
`adb`,
`install`,
`-r`,
androidPkgName(filepath.Base(pkg.Dir))+`.apk`,
)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if buildX || buildN {
printcmd("%s", strings.Join(c.Args, " "))
}
if buildN {
return nil
}
return c.Run()
}