diff --git a/cmd/gomobile/bind_test.go b/cmd/gomobile/bind_test.go index 5970c04..0e9f401 100644 --- a/cmd/gomobile/bind_test.go +++ b/cmd/gomobile/bind_test.go @@ -67,7 +67,7 @@ func TestBindAndroid(t *testing.T) { } got := filepath.ToSlash(buf.String()) - output, err := defaultOutputData() + output, err := defaultOutputData("") if err != nil { t.Fatal(err) } @@ -148,7 +148,7 @@ func TestBindApple(t *testing.T) { } got := filepath.ToSlash(buf.String()) - output, err := defaultOutputData() + output, err := defaultOutputData("") if err != nil { t.Fatal(err) } diff --git a/cmd/gomobile/build_apple.go b/cmd/gomobile/build_apple.go index 2adaf3d..9ec2056 100644 --- a/cmd/gomobile/build_apple.go +++ b/cmd/gomobile/build_apple.go @@ -40,11 +40,24 @@ func goAppleBuild(pkg *packages.Package, bundleID string, targets []targetInfo) return nil, err } + // Detect the team ID + teamID, err := detectTeamID() + if err != nil { + return nil, err + } + + projPbxproj := new(bytes.Buffer) + if err := projPbxprojTmpl.Execute(projPbxproj, projPbxprojTmplData{ + TeamID: teamID, + }); err != nil { + return nil, err + } + files := []struct { name string contents []byte }{ - {tmpdir + "/main.xcodeproj/project.pbxproj", []byte(projPbxproj)}, + {tmpdir + "/main.xcodeproj/project.pbxproj", projPbxproj.Bytes()}, {tmpdir + "/main/Info.plist", infoplist.Bytes()}, {tmpdir + "/main/Images.xcassets/AppIcon.appiconset/Contents.json", []byte(contentsJSON)}, } @@ -106,12 +119,6 @@ func goAppleBuild(pkg *packages.Package, bundleID string, targets []targetInfo) return nil, err } - // Detect the team ID - teamID, err := detectTeamID() - if err != nil { - return nil, err - } - // Build and move the release build to the output directory. cmdStrings := []string{ "xcodebuild", @@ -282,7 +289,11 @@ var infoplistTmpl = template.Must(template.New("infoplist").Parse(` `)) -const projPbxproj = `// !$*UTF8*$! +type projPbxprojTmplData struct { + TeamID string +} + +var projPbxprojTmpl = template.Must(template.New("projPbxproj").Parse(`// !$*UTF8*$! { archiveVersion = 1; classes = { @@ -370,6 +381,7 @@ const projPbxproj = `// !$*UTF8*$! TargetAttributes = { 254BB83D1B1FD08900C56DE9 = { CreatedOnToolsVersion = 6.3.1; + DevelopmentTeam = {{.TeamID}}; }; }; }; @@ -476,7 +488,7 @@ const projPbxproj = `// !$*UTF8*$! }; rootObject = 254BB8361B1FD08900C56DE9 /* Project object */; } -` +`)) const contentsJSON = `{ "images" : [ diff --git a/cmd/gomobile/build_darwin_test.go b/cmd/gomobile/build_darwin_test.go index 2fac27c..bb87701 100644 --- a/cmd/gomobile/build_darwin_test.go +++ b/cmd/gomobile/build_darwin_test.go @@ -61,7 +61,7 @@ func TestAppleBuild(t *testing.T) { t.Fatalf("detecting team ID failed: %v", err) } - output, err := defaultOutputData() + output, err := defaultOutputData(teamID) if err != nil { t.Fatal(err) } diff --git a/cmd/gomobile/init_test.go b/cmd/gomobile/init_test.go index ee48513..4dfc706 100644 --- a/cmd/gomobile/init_test.go +++ b/cmd/gomobile/init_test.go @@ -123,7 +123,7 @@ func diffOutput(got string, wantTmpl *template.Template) (string, error) { got = filepath.ToSlash(got) wantBuf := new(bytes.Buffer) - data, err := defaultOutputData() + data, err := defaultOutputData("") if err != nil { return "", err } @@ -148,13 +148,20 @@ type outputData struct { Xinfo infoplistTmplData } -func defaultOutputData() (outputData, error) { +func defaultOutputData(teamID string) (outputData, error) { + projPbxproj := new(bytes.Buffer) + if err := projPbxprojTmpl.Execute(projPbxproj, projPbxprojTmplData{ + TeamID: teamID, + }); err != nil { + return outputData{}, err + } + data := outputData{ GOOS: goos, GOARCH: goarch, GOPATH: gopath, NDKARCH: archNDK(), - Xproj: projPbxproj, + Xproj: projPbxproj.String(), Xcontents: contentsJSON, Xinfo: infoplistTmplData{BundleID: "org.golang.todo.basic", Name: "Basic"}, }