go goes mobile: quick exploration on go 1.5 and gomobile
TRANSCRIPT
Go goes Mobile!~Quick Exploration on Go 1.5 and Gomobile~
Takahiro Yoshimura (@alterakey) 26.9.2015
Who am I?
株式会社モノリスワークスR&D
Twitter→@alterakey
What's Go?
Googleが開発している言語
ビルドが速い静的型付け言語
並列・ネットワーク系処理
自動メモリ管理
軽量かつ強力な型システム
… https://golang.org/
What's Android?
Google主導で開発している モバイルプラットフォーム
全世界で81.8%のシェア(IDC 2014)
言わずもがな…https://www.android.com/
Photo by flickr user khamtram, used on CC BY 2.0 license
Go and Android
Goが生成するのはネイティブバイナリ
AndroidはDalvik VM+JNI
Gomobile!
AndroidやiOSのバイナリを出せるツールチェイン(ARM only; Go 1.5~)
https://github.com/golang/mobile
Go 1.5
ここからダウンロードしてインストールhttps://golang.org/dl/
GOPATHの設定についてhttps://gist.github.com/taky/bac1cb4956ea19a0bce5→<path>/bin/activateとしておき、sourceする前提
Gomobile
ツールチェインの初期設定
source ./bin/activatego get golang.org/x/mobile/cmd/gomobilegomobile init
Example: basic
OpenGLを使って描画するアプリ
go get -d golang.org/x/mobile/example/basicgomobile build golang.org/x/mobile/example/basic# install APKgomobile install golang.org/x/mobile/example/basic
Example: bind
Goで書いたロジックをJavaから呼びだす
bindingを生成するGradle Pluginがある
golang.org/x/mobile/example/bind/android
build.gradle: GOPATH and GO
Example: bind
android/app/...MainActivity.java:String ... = Hello.Greetings("...")
hello/hello.go:func Greetings(name string) ... return fmt.Sprintf("Hello, %s!", name)→ "Hello, Android and Gopher!"
Conclusion
AndroidとiOS用のバイナリをGoから生成可能
アプリを0から書くこともできるが……
共通ロジックを記述する一つの方法
fin.