diff --git a/cmd/gomobile/build_androidapp.go b/cmd/gomobile/build_androidapp.go
index 9b0b689..9b4588e 100644
--- a/cmd/gomobile/build_androidapp.go
+++ b/cmd/gomobile/build_androidapp.go
@@ -29,11 +29,17 @@ func goAndroidBuild(pkg *build.Package) (map[string]bool, error) {
if !os.IsNotExist(err) {
return nil, err
}
+
+ productName := rfc1034Label(libName)
+ if productName == "" {
+ productName = "ProductName" // like xcode.
+ }
+
buf := new(bytes.Buffer)
buf.WriteString(``)
err := manifestTmpl.Execute(buf, manifestTmplData{
// TODO(crawshaw): a better package path.
- JavaPkgPath: "org.golang.todo." + libName,
+ JavaPkgPath: "org.golang.todo." + productName,
Name: libName,
LibName: libName,
})
diff --git a/cmd/gomobile/build_iosapp.go b/cmd/gomobile/build_iosapp.go
index 252db6b..48bb19d 100644
--- a/cmd/gomobile/build_iosapp.go
+++ b/cmd/gomobile/build_iosapp.go
@@ -23,9 +23,16 @@ func goIOSBuild(pkg *build.Package) (map[string]bool, error) {
return nil, fmt.Errorf("-o must have an .app for target=ios")
}
+ productName := rfc1034Label(path.Base(pkg.ImportPath))
+ if productName == "" {
+ productName = "ProductName" // like xcode.
+ }
+
infoplist := new(bytes.Buffer)
- if err := infoplistTmpl.Execute(infoplist, manifestTmplData{
- Name: strings.Title(path.Base(pkg.ImportPath)),
+ if err := infoplistTmpl.Execute(infoplist, infoplistTmplData{
+ // TODO: better bundle id.
+ BundleID: "org.golang.todo." + productName,
+ Name: strings.Title(path.Base(pkg.ImportPath)),
}); err != nil {
return nil, err
}
@@ -147,7 +154,8 @@ func iosCopyAssets(pkg *build.Package, xcodeProjDir string) error {
}
type infoplistTmplData struct {
- Name string
+ BundleID string
+ Name string
}
var infoplistTmpl = template.Must(template.New("infoplist").Parse(`
@@ -159,7 +167,7 @@ var infoplistTmpl = template.Must(template.New("infoplist").Parse(`CFBundleExecutable
mainCFBundleIdentifier
- org.golang.todo.$(PRODUCT_NAME:rfc1034identifier)
+ {{.BundleID}}CFBundleInfoDictionaryVersion6.0CFBundleName
@@ -518,3 +526,61 @@ const contentsJSON = `{
}
}
`
+
+// rfc1034Label sanitizes the name to be usable in a uniform type identifier.
+// The sanitization is similar to xcode's rfc1034identifier macro that
+// replaces illegal characters (not conforming the rfc1034 label rule) with '-'.
+func rfc1034Label(name string) string {
+ // * Uniform type identifier:
+ //
+ // According to
+ // https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html
+ //
+ // A uniform type identifier is a Unicode string that usually contains characters
+ // in the ASCII character set. However, only a subset of the ASCII characters are
+ // permitted. You may use the Roman alphabet in upper and lower case (A–Z, a–z),
+ // the digits 0 through 9, the dot (“.”), and the hyphen (“-”). This restriction
+ // is based on DNS name restrictions, set forth in RFC 1035.
+ //
+ // Uniform type identifiers may also contain any of the Unicode characters greater
+ // than U+007F.
+ //
+ // Note: the actual implementation of xcode does not allow some unicode characters
+ // greater than U+007f. In this implementation, we just replace everything non
+ // alphanumeric with "-" like the rfc1034identifier macro.
+ //
+ // * RFC1034 Label
+ //
+ //