go goes mobile: quick exploration on go 1.5 and gomobile

13
Go goes Mobile! ~Quick Exploration on Go 1.5 and Gomobile~ Takahiro Yoshimura (@alterakey) 26.9.2015

Upload: takahiro-yoshimura

Post on 13-Apr-2017

573 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Go goes Mobile!~Quick Exploration on Go 1.5 and Gomobile~

Takahiro Yoshimura (@alterakey) 26.9.2015

Page 2: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Who am I?

株式会社モノリスワークスR&D

Twitter→@alterakey

Page 3: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

What's Go?

Googleが開発している言語

ビルドが速い静的型付け言語

並列・ネットワーク系処理

自動メモリ管理

軽量かつ強力な型システム

… https://golang.org/

Page 4: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

What's Android?

Google主導で開発している モバイルプラットフォーム

全世界で81.8%のシェア(IDC 2014)

言わずもがな…https://www.android.com/

Photo by flickr user khamtram, used on CC BY 2.0 license

Page 5: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Go and Android

Goが生成するのはネイティブバイナリ

AndroidはDalvik VM+JNI

Page 6: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Gomobile!

AndroidやiOSのバイナリを出せるツールチェイン(ARM only; Go 1.5~)

https://github.com/golang/mobile

Page 7: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Go 1.5

ここからダウンロードしてインストールhttps://golang.org/dl/

GOPATHの設定についてhttps://gist.github.com/taky/bac1cb4956ea19a0bce5→<path>/bin/activateとしておき、sourceする前提

Page 8: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Gomobile

ツールチェインの初期設定

source ./bin/activatego get golang.org/x/mobile/cmd/gomobilegomobile init

Page 9: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

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

Page 10: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Example: bind

Goで書いたロジックをJavaから呼びだす

bindingを生成するGradle Pluginがある

golang.org/x/mobile/example/bind/android

build.gradle: GOPATH and GO

Page 11: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

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!"

Page 12: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

Conclusion

AndroidとiOS用のバイナリをGoから生成可能

アプリを0から書くこともできるが……

共通ロジックを記述する一つの方法

Page 13: Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile

fin.