Saturday, June 24, 2017

Gomobile in MAC

gomobile

Gomobile Installed in Mac

Download pkg

You might download golang's latest release in Mac.

https://storage.googleapis.com/golang/go1.8.3.darwin-amd64.pkg

And intall it by double click it.

Environment

It will install package under /Users/xxx/go

junmeinde-MacBook-Pro:src junmein$ pwd
/Users/junmein/go/src

Adding GOPATH

junmeinde-MacBook-Pro:src junmein$ export GOPATH=/Users/junmein/go

Install Gomobile and Build Framework In Mac

Get gomobile

go get golang.org/x/mobile/cmd/gomobile

Binding You golang code to IOS

junmeinde-MacBook-Pro:src junmein$ /Users/junmein/go/bin/gomobile bind -target=ios golang.org/x/mobile/example/bind/hello

You will get Hello.framework for IOS

junmeinde-MacBook-Pro:src junmein$ ls
Hello.framework golang.org

Compile Hello.Framework in Xcode

Put Hello.Framework in xcode

drag and drop hello.framework to xcode project

Adding code to existed code

import Hello
.
.
.
let msg = HelloGreetings("golang haha")

Disable Bitcode check

Project -> search -> bicode -> no

If you ignore this steps, it will case the errors

error 
link comand failed xcode framework

Thanks for this blog, it really help me a lot

https://medium.com/@fzambia/going-mobile-adapting-centrifugo-go-websocket-client-to-be-used-for-ios-and-android-app-e72dc2736f01

Result

You can download the result from my github

https://github.com/jonahwu/gomobile

More

Gomobile Installed in Ubuntu

It failed and with this exception.

/root/golang/bin/gomobile: exec: "xcrun": executable file not found in $PATH

More Reference

https://medium.com/@fzambia/going-mobile-adapting-centrifugo-go-websocket-client-to-be-used-for-ios-and-android-app-e72dc2736f01

http://blog.csdn.net/win_lin/article/details/48265493
http://blog.csdn.net/win_lin/article/details/60956485

No comments:

Post a Comment