SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
Mobile Apps
by Pure Go
with Reverse Binding
GopherCon India
22nd Feb. 2017
The Go gopher was designed by Renee French.
The gopher stickers was made by Takuya Ueda.
Licensed under the Creative Commons 3.0
Attributions license.
Slide URL: https://goo.gl/OG55gT
Slide URL: https://goo.gl/OG55gT
Who am I?
Mercari, Inc./Souzoh, Inc.
Takuya Ueda
twitter: @tenntenn
■ Communities
Google Cloud Platform User Group (GCPUG) Tokyo
Go Beginners in Tokyo, Japan
golang.tokyo
Go Conference in Tokyo, Japan
■ Works
Developing Mercari Atte in GAE/Go
2
Slide URL: https://goo.gl/OG55gT
What is this talk about?
● The Basics of Go Mobile
○ Cross-compile / cgo for Android
○ What is Go Mobile?
○ SDK Apps and Native Apps
● Developing Android Apps in pure Go
○ gomobile bind
○ What is Reverse Bindings?
○ Use Platform APIs from Go
3
Slide URL: https://goo.gl/OG55gT
The Basics of Go Mobile
4
Slide URL: https://goo.gl/OG55gT
Cross-compile
● GOOS and GOARCH
○ Go can cross-compile
○ GOOS indicates target OS
○ GOARCH indicates target architecture
5
# Build for 32bit Windows
$ GOOS=windows GOARCH=386 go build
# Build for arm Linux
$ GOOS=linux GOARCH=arm go build
A linux/arm binary also works on android devices.
Slide URL: https://goo.gl/OG55gT
Web server on Android Device
6
Watch at Youtube Source Code
Android
Shell on Mac
adb shell
Slide URL: https://goo.gl/OG55gT
cgo
● C codes into Go codes
7
import "unsafe"
/*
#include <stdio.h>
#include <stdlib.h>
void hello(char *s) { printf("Hello, %sn", s); }
*/
import "C"
func main() {
str := C.CString("GopherCon India")
C.hello(str)
C.free(unsafe.Pointer(str))
}
Comments before import "C"
would be built as C codes
Call C’s function from Go code
Slide URL: https://goo.gl/OG55gT
cgo for Android
● cgo codes also can be cross-compiled
8
$ CGO_ENABLED=1
CC=arm-linux-androideabi-gcc
GOOS=android
GOARCH=arm
GOARM=7
go build -buildmode=pie hellocgo.go
$ adb push hellocgo /data/local/tmp
$ chmod 755 /data/local/tmp/hellocgo
$ /data/local/tmp/hellocgo
Hello, GopherCon India
GOOS should be android
when CGO_ENABLED is 1.
Enable cgo at cross-compiling
adb shell
PC
Slide URL: https://goo.gl/OG55gT
buildmode
● Change output formats
○ archive, c-archive
■ build into C archive (.a file)
○ shared, c-shared
■ build into shared library (.so file)
○ plugin
■ bulid into Go Plugin (<= Go 1.8)
○ exe
■ build into executable file
○ pie
■ build into PIE style executable file
9
archive and
shared ignore
main package
Go can build to .so files for Android
Slide URL: https://goo.gl/OG55gT
Go Mobile
● What is Go Mobile?
○ Go Mobile is a toolkit for Mobile Platform
(Android and iOS) in Go.
● How Go Mobile works?
○ Go Mobile provides bindings of Android
and iOS through cgo.
10
Go C
Java
Obj-C
JNIcgo
Android
iOS
Slide URL: https://goo.gl/OG55gT
Go Mobile
11
https://github.com/golang/mobile
Slide URL: https://goo.gl/OG55gT
Installation
● Install gomobile comand
● Initialize the build tool chain
○ gomobile init initializes the build tool
chain for mobile apps.
12
$ gomobile init -v
$ ls $GOPATH/pkg/gomobile
android_ndk_root pkg_android_amd64
pkg_android_arm64 pkg_darwin_arm version
pkg_android_386 pkg_android_arm
pkg_darwin_amd64 pkg_darwin_arm64
$ go get -u golang.org/x/mobile/cmd/gomobile
Slide URL: https://goo.gl/OG55gT
gomobile command
gomobile command provides sub-commands.
● Sub-commands
13
bind build a library for Android and iOS
build compile Android APK and iOS app
clean remove object files and cached gomobile files
init install android compiler toolchain
install compile android APK and install on device
version print version
Slide URL: https://goo.gl/OG55gT
SDK Apps and Native Apps
Go Mobile provides two ways to develop mobile
apps.
■ SDK Apps
● Write common funcations in Go as a
library
■ Native Apps
● Write UI and all codes in Go
14
Slide URL: https://goo.gl/OG55gT
SDK Apps and Native Apps
● SDK Apps for Android
● Native Apps for Android
15
Go
aar file
Binding Classes (Java)
Shared library (.so)
Java
UI, IAB, ...
As a library
gomobile bind
apk file
Go
GoNativeActivity
Shared library (.so)UI, audio, ...
gomobile build
Slide URL: https://goo.gl/OG55gT
An Example of SDK Apps: Ivy
● Ivy big number calculator (source code)
○ Interpriter for APL-like language
○ Android App and iOS App use a same engine
○ The engine is written in Go by Rob Pike
16
Google Play App Store
Slide URL: https://goo.gl/OG55gT
An Example of Native Apps
● Flappy Gopher
○ A mobile game written in Go Mobile
○ Developed by Andrew Gerrand
for Go Conference 2015 Winter
○ Source Code
17
Slide URL: https://goo.gl/OG55gT
Developing Android Apps
in Pure Go
18
Slide URL: https://goo.gl/OG55gT
gomobile bind
● Generate an Android Archive (.aar)
○ a shared library (.so) written in Go
○ a JAR file which is bult Java bindings
● Develop with Android Studio Plugin
○ Runs gomobile bind
○ Links to a generated .aar file
19
$ gomobile bind [-target ios|android] mypkg
Slide URL: https://goo.gl/OG55gT
Contents of an AAR file
20
$ gomobile bind sample
$ unzip -Z1 sample.aar
AndroidManifest.xml
proguard.txt
classes.jar
jni/armeabi-v7a/libgojni.so
jni/arm64-v8a/libgojni.so
jni/x86/libgojni.so
jni/x86_64/libgojni.so
R.txt
res/
Compiled Java codes
Compiled
Go/C codes
Slide URL: https://goo.gl/OG55gT
Calling Go code from Java code
21
Bindings
Java codes
Application Codes
(Java)
C codes
Go/cgo codes
JNI Generated by
gomobile bind
SDK Codes
(Go)
cgo
Slide URL: https://goo.gl/OG55gT
An Example of Bindings
22
package sample
func Hello() string { return "Hello" }
type MyStruct struct { Str string }
func (s MyStruct) MyMethod() string { return s.Str }
public abstract class Sample {
// ...
private Sample() {} // uninstantiable
public static final class MyStruct extends Seq.Proxy {
public final native String getStr();
public final native void setStr(String v);
public native String MyMethod();
// ...
}
public static native String Hello();
}
Java
Go
Struct
Field
Method
Package Function
Slide URL: https://goo.gl/OG55gT
Type restrictions
● Signed integer and floating point type
● String and boolean type
● Byte slice type
● Any functions
○ parameter and result types must be supported types
○ results are 0, 1 or 2 (2nd result must be an error
type)
● Any struct type
○ all fields and methods must be supported types
● Any interface
○ all methods must be supported types
23
Slide URL: https://goo.gl/OG55gT
Calling Platform API from Go
● In-app Billing
○ Purchase a items in the game
● SNS connection
○ Facebook, Twitter, ...
● Advertisements
● Analytics
○ Google Analytics, Firebase, Facebook
Analytics,...
24
These APIs are provided
as Java SDK for Android
Slide URL: https://goo.gl/OG55gT
Traditional gomobile bind
● Bindings to Go from Java/Obj-C
● Platform APIs can be accessed BUT...
○ Indirect way
○ Needs wrappers
○ Not convenient
25
A way to access directly
Platform APIs from Go is needed!
Slide URL: https://goo.gl/OG55gT
Reverse Bindings
● Access Platform APIs from Go
● Generate bindings automatically
○ Reverse direction of traditional one
○ use gomobile bind
● Prposed by #16876 and #17102
(Android) (iOS)
26
Slide URL: https://goo.gl/OG55gT
Reverse Bindings
27
Bindings
Java codes
Go Codes
C codes
Go/cgo codes
JNI
Generated by
gomobile bind
Platform APIs
(Java)
cgo
Slide URL: https://goo.gl/OG55gT
An Example of Reverse Bindings
28
package pkg
import "Java/java/lang"
import "Java/pkg"
type Obj struct {
lang.Object
}
func (h *Obj) ToString(this *pkg.Obj) string {
return "hoge"
}
● Parse import statements
○ Java/* or ObjC/*
● Generate bindings automatically
corresponds java.lang
package in Java
inherit java.lang.Object
Hold a Java instance
Slide URL: https://goo.gl/OG55gT
How Generate Reverse Bindings?
● Parse import statements
○ Begin with Java/
● Extract class infomation by javap
○ Exported fields and methods
○ Dependent classes
○ Implementing interfaces
● Generate bindings of all dependented
classes and interfaces
29
$ javap java.lang.String
Compiled from "String.java"
public final class java.lang.String implements java.io.Serializable,
java.lang.Comparable<java.lang.String>, java.lang.CharSequence {
public static final java.util.Comparator<java.lang.String>
CASE_INSENSITIVE_ORDER;
public java.lang.String();
....
Slide URL: https://goo.gl/OG55gT
Using Platform APIs from Go
● Example of Reverse Binding in x/mobile
30
$ cd $GOPATH/src/golang.org/x/mobile
$ cd example/reverse/android
$ gradle wrapper
$ ./gradlew build
$ cd build/outputs/apk
$ adb install -r android-debug.apk
Android Studio
also can build
Slide URL: https://goo.gl/OG55gT
Use Platform APIs from Go
● Use Activity and write in life cycle of
Android
31
type MainActivity struct {
app.AppCompatActivity
binding databinding.ActivityMainBinding
}
func (a *MainActivity) OnCreate(
this gopkg.MainActivity, b os.Bundle) {
...
}
func (a *MainActivity) OnDestroy(
this gopkg.MainActivity) {
...
}
reverse.go
Slide URL: https://goo.gl/OG55gT
Use Platform APIs from Go
● Use data binding of Android
32
func (a *MainActivity) OnCreate(
this gopkg.MainActivity, b os.Bundle) {
this.Super().OnCreate(b)
db := DataBindingUtil.SetContentView(
this, rlayout.Activity_main)
a.binding = ActivityMainBinding.Cast(db)
a.binding.SetAct(this)
}
func (a *MainActivity) GetLabel() string {
return "Hello, GopherCon India!"
}
reverse.go
Slide URL: https://goo.gl/OG55gT
Use Platform APIs from Go
● Use data binding of Android
33
...
<data>
<variable name="act"
type="reverse.MainActivity"/>
</data>
<RelativeLayout ...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{act.label}"/>
</RelativeLayout>
</layout>
activity_main.xml
Slide URL: https://goo.gl/OG55gT
Summaries
● The Basics of Go Mobile
○ Cross-compile / cgo for Android
○ What is Go Mobile?
○ SDK Apps and Native Apps
● Developing Android Apps in pure Go
○ gomobile bind
○ What is Reverse Bindings?
○ Use Platform APIs from Go
34
Thank you!
twitter: @tenntenn
Qiita: tenntenn
35
Slide URL: https://goo.gl/OG55gT
Binding between Go and Java
36
Package Abstruct Class
Struct Inner Class
Struct Field
Getter/Setter
(Native)
Method Method
(Native)
Package Function Static Method
Go Java
● gomobile bind generates bindings

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

IP and VoIP Fundamentals
IP and VoIP FundamentalsIP and VoIP Fundamentals
IP and VoIP Fundamentals
 
Ipv6
Ipv6Ipv6
Ipv6
 
Wireless usb
Wireless usbWireless usb
Wireless usb
 
DDOS ATTACK - MIRAI BOTNET
DDOS ATTACK - MIRAI BOTNET DDOS ATTACK - MIRAI BOTNET
DDOS ATTACK - MIRAI BOTNET
 
Introduction To Open Source Licensing
Introduction To Open Source LicensingIntroduction To Open Source Licensing
Introduction To Open Source Licensing
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IO
 
introduction to Botnet
introduction to Botnetintroduction to Botnet
introduction to Botnet
 
Assignment 1 iap
Assignment 1 iapAssignment 1 iap
Assignment 1 iap
 
Fuzzing.pptx
Fuzzing.pptxFuzzing.pptx
Fuzzing.pptx
 
Sequence detector for "111"
Sequence detector for "111"Sequence detector for "111"
Sequence detector for "111"
 
Seven segment display
Seven segment display Seven segment display
Seven segment display
 
红蓝对抗之隐蔽通信应用及防御.pptx
红蓝对抗之隐蔽通信应用及防御.pptx红蓝对抗之隐蔽通信应用及防御.pptx
红蓝对抗之隐蔽通信应用及防御.pptx
 
WiFi
WiFiWiFi
WiFi
 
XBOX 360
XBOX 360XBOX 360
XBOX 360
 
Methods to Bypass a Web Application Firewall Eng
Methods to Bypass a Web Application Firewall EngMethods to Bypass a Web Application Firewall Eng
Methods to Bypass a Web Application Firewall Eng
 
IANAL: what developers should know about IP and Legal
IANAL: what developers should know about IP and LegalIANAL: what developers should know about IP and Legal
IANAL: what developers should know about IP and Legal
 
Api security-testing
Api security-testingApi security-testing
Api security-testing
 
transistor transistor logic
transistor transistor logictransistor transistor logic
transistor transistor logic
 
Wireless Fidelity ppt
Wireless Fidelity pptWireless Fidelity ppt
Wireless Fidelity ppt
 
Shellshock - A Software Bug
Shellshock - A Software BugShellshock - A Software Bug
Shellshock - A Software Bug
 

Destaque

静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話
静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話
静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話Takuya Ueda
 
goパッケージで型情報を用いたソースコード検索を実現する
goパッケージで型情報を用いたソースコード検索を実現するgoパッケージで型情報を用いたソースコード検索を実現する
goパッケージで型情報を用いたソースコード検索を実現するTakuya Ueda
 
Cloud Functionsの紹介
Cloud Functionsの紹介Cloud Functionsの紹介
Cloud Functionsの紹介Takuya Ueda
 
Goにおける静的解析と製品開発への応用
Goにおける静的解析と製品開発への応用Goにおける静的解析と製品開発への応用
Goにおける静的解析と製品開発への応用Takuya Ueda
 
Namespace API を用いたマルチテナント型 Web アプリの実践
Namespace API を用いたマルチテナント型 Web アプリの実践Namespace API を用いたマルチテナント型 Web アプリの実践
Namespace API を用いたマルチテナント型 Web アプリの実践Takuya Ueda
 
うしちゃん WebRTC Chat on SkyWayの開発コードw
うしちゃん WebRTC Chat on SkyWayの開発コードwうしちゃん WebRTC Chat on SkyWayの開発コードw
うしちゃん WebRTC Chat on SkyWayの開発コードwKensaku Komatsu
 
Go静的解析ハンズオン
Go静的解析ハンズオンGo静的解析ハンズオン
Go静的解析ハンズオンTakuya Ueda
 
Javaトラブルに備えよう #jjug_ccc #ccc_h2
Javaトラブルに備えよう #jjug_ccc #ccc_h2Javaトラブルに備えよう #jjug_ccc #ccc_h2
Javaトラブルに備えよう #jjug_ccc #ccc_h2Norito Agetsuma
 
HTTP2 RFC 発行記念祝賀会
HTTP2 RFC 発行記念祝賀会HTTP2 RFC 発行記念祝賀会
HTTP2 RFC 発行記念祝賀会Jxck Jxck
 
条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化Takuya Ueda
 
粗探しをしてGoのコントリビューターになる方法
粗探しをしてGoのコントリビューターになる方法粗探しをしてGoのコントリビューターになる方法
粗探しをしてGoのコントリビューターになる方法Takuya Ueda
 
Go1.8 for Google App Engine
Go1.8 for Google App EngineGo1.8 for Google App Engine
Go1.8 for Google App EngineTakuya Ueda
 
Static Analysis in Go
Static Analysis in GoStatic Analysis in Go
Static Analysis in GoTakuya Ueda
 
GoによるiOSアプリの開発
GoによるiOSアプリの開発GoによるiOSアプリの開発
GoによるiOSアプリの開発Takuya Ueda
 
メルカリ・ソウゾウでは どうGoを活用しているのか?
メルカリ・ソウゾウでは どうGoを活用しているのか?メルカリ・ソウゾウでは どうGoを活用しているのか?
メルカリ・ソウゾウでは どうGoを活用しているのか?Takuya Ueda
 
Cloud functionsの紹介
Cloud functionsの紹介Cloud functionsの紹介
Cloud functionsの紹介Takuya Ueda
 
HTTP2 時代の Web - web over http2
HTTP2 時代の Web - web over http2HTTP2 時代の Web - web over http2
HTTP2 時代の Web - web over http2Jxck Jxck
 
Google Assistant関係のセッションまとめ
Google Assistant関係のセッションまとめGoogle Assistant関係のセッションまとめ
Google Assistant関係のセッションまとめTakuya Ueda
 
オススメの標準・準標準パッケージ20選
オススメの標準・準標準パッケージ20選オススメの標準・準標準パッケージ20選
オススメの標準・準標準パッケージ20選Takuya Ueda
 
WebRTC Browsers n Stacks Implementation differences
WebRTC Browsers n Stacks Implementation differencesWebRTC Browsers n Stacks Implementation differences
WebRTC Browsers n Stacks Implementation differencesAlexandre Gouaillard
 

Destaque (20)

静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話
静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話
静的解析とUIの自動生成を駆使してモバイルアプリの運用コストを大幅に下げた話
 
goパッケージで型情報を用いたソースコード検索を実現する
goパッケージで型情報を用いたソースコード検索を実現するgoパッケージで型情報を用いたソースコード検索を実現する
goパッケージで型情報を用いたソースコード検索を実現する
 
Cloud Functionsの紹介
Cloud Functionsの紹介Cloud Functionsの紹介
Cloud Functionsの紹介
 
Goにおける静的解析と製品開発への応用
Goにおける静的解析と製品開発への応用Goにおける静的解析と製品開発への応用
Goにおける静的解析と製品開発への応用
 
Namespace API を用いたマルチテナント型 Web アプリの実践
Namespace API を用いたマルチテナント型 Web アプリの実践Namespace API を用いたマルチテナント型 Web アプリの実践
Namespace API を用いたマルチテナント型 Web アプリの実践
 
うしちゃん WebRTC Chat on SkyWayの開発コードw
うしちゃん WebRTC Chat on SkyWayの開発コードwうしちゃん WebRTC Chat on SkyWayの開発コードw
うしちゃん WebRTC Chat on SkyWayの開発コードw
 
Go静的解析ハンズオン
Go静的解析ハンズオンGo静的解析ハンズオン
Go静的解析ハンズオン
 
Javaトラブルに備えよう #jjug_ccc #ccc_h2
Javaトラブルに備えよう #jjug_ccc #ccc_h2Javaトラブルに備えよう #jjug_ccc #ccc_h2
Javaトラブルに備えよう #jjug_ccc #ccc_h2
 
HTTP2 RFC 発行記念祝賀会
HTTP2 RFC 発行記念祝賀会HTTP2 RFC 発行記念祝賀会
HTTP2 RFC 発行記念祝賀会
 
条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化
 
粗探しをしてGoのコントリビューターになる方法
粗探しをしてGoのコントリビューターになる方法粗探しをしてGoのコントリビューターになる方法
粗探しをしてGoのコントリビューターになる方法
 
Go1.8 for Google App Engine
Go1.8 for Google App EngineGo1.8 for Google App Engine
Go1.8 for Google App Engine
 
Static Analysis in Go
Static Analysis in GoStatic Analysis in Go
Static Analysis in Go
 
GoによるiOSアプリの開発
GoによるiOSアプリの開発GoによるiOSアプリの開発
GoによるiOSアプリの開発
 
メルカリ・ソウゾウでは どうGoを活用しているのか?
メルカリ・ソウゾウでは どうGoを活用しているのか?メルカリ・ソウゾウでは どうGoを活用しているのか?
メルカリ・ソウゾウでは どうGoを活用しているのか?
 
Cloud functionsの紹介
Cloud functionsの紹介Cloud functionsの紹介
Cloud functionsの紹介
 
HTTP2 時代の Web - web over http2
HTTP2 時代の Web - web over http2HTTP2 時代の Web - web over http2
HTTP2 時代の Web - web over http2
 
Google Assistant関係のセッションまとめ
Google Assistant関係のセッションまとめGoogle Assistant関係のセッションまとめ
Google Assistant関係のセッションまとめ
 
オススメの標準・準標準パッケージ20選
オススメの標準・準標準パッケージ20選オススメの標準・準標準パッケージ20選
オススメの標準・準標準パッケージ20選
 
WebRTC Browsers n Stacks Implementation differences
WebRTC Browsers n Stacks Implementation differencesWebRTC Browsers n Stacks Implementation differences
WebRTC Browsers n Stacks Implementation differences
 

Semelhante a Mobile Apps by Pure Go with Reverse Binding

Go for Mobile Games
Go for Mobile GamesGo for Mobile Games
Go for Mobile GamesTakuya Ueda
 
Develop Android app using Golang
Develop Android app using GolangDevelop Android app using Golang
Develop Android app using GolangSeongJae Park
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golangSeongJae Park
 
GTG30: Introduction vgo
GTG30: Introduction vgoGTG30: Introduction vgo
GTG30: Introduction vgoEvan Lin
 
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)Evan Lin
 
Android is going to Go! Android and Golang
Android is going to Go! Android and GolangAndroid is going to Go! Android and Golang
Android is going to Go! Android and GolangAlmog Baku
 
Android is going to Go! - Android and goland - Almog Baku
Android is going to Go! - Android and goland - Almog BakuAndroid is going to Go! - Android and goland - Almog Baku
Android is going to Go! - Android and goland - Almog BakuDroidConTLV
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Pythonwesley chun
 
(Live) build and run golang web server on android.avi
(Live) build and run golang web server on android.avi(Live) build and run golang web server on android.avi
(Live) build and run golang web server on android.aviSeongJae Park
 
Introduction google glass en - rev 20 - codemotion
Introduction google glass   en - rev 20 - codemotionIntroduction google glass   en - rev 20 - codemotion
Introduction google glass en - rev 20 - codemotionCodemotion
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
Build and Deploy a Python Web App to Amazon in 30 Mins
Build and Deploy a Python Web App to Amazon in 30 MinsBuild and Deploy a Python Web App to Amazon in 30 Mins
Build and Deploy a Python Web App to Amazon in 30 MinsJeff Hull
 
Porting golang development environment developed with golang
Porting golang development environment developed with golangPorting golang development environment developed with golang
Porting golang development environment developed with golangSeongJae Park
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...Andy Maleh
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity SecuritySeungmin Shin
 
Create Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGapCreate Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGapSteve Phillips
 
Building Translate on Glass
Building Translate on GlassBuilding Translate on Glass
Building Translate on GlassTrish Whetzel
 

Semelhante a Mobile Apps by Pure Go with Reverse Binding (20)

Go for Mobile Games
Go for Mobile GamesGo for Mobile Games
Go for Mobile Games
 
Develop Android app using Golang
Develop Android app using GolangDevelop Android app using Golang
Develop Android app using Golang
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golang
 
Go, meet Lua
Go, meet LuaGo, meet Lua
Go, meet Lua
 
GTG30: Introduction vgo
GTG30: Introduction vgoGTG30: Introduction vgo
GTG30: Introduction vgo
 
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
 
Android is going to Go! Android and Golang
Android is going to Go! Android and GolangAndroid is going to Go! Android and Golang
Android is going to Go! Android and Golang
 
Android is going to Go! - Android and goland - Almog Baku
Android is going to Go! - Android and goland - Almog BakuAndroid is going to Go! - Android and goland - Almog Baku
Android is going to Go! - Android and goland - Almog Baku
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Python
 
(Live) build and run golang web server on android.avi
(Live) build and run golang web server on android.avi(Live) build and run golang web server on android.avi
(Live) build and run golang web server on android.avi
 
Introduction google glass en - rev 20 - codemotion
Introduction google glass   en - rev 20 - codemotionIntroduction google glass   en - rev 20 - codemotion
Introduction google glass en - rev 20 - codemotion
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Build and Deploy a Python Web App to Amazon in 30 Mins
Build and Deploy a Python Web App to Amazon in 30 MinsBuild and Deploy a Python Web App to Amazon in 30 Mins
Build and Deploy a Python Web App to Amazon in 30 Mins
 
Porting golang development environment developed with golang
Porting golang development environment developed with golangPorting golang development environment developed with golang
Porting golang development environment developed with golang
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity Security
 
Create Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGapCreate Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGap
 
Android Made Simple
Android Made SimpleAndroid Made Simple
Android Made Simple
 
Building Translate on Glass
Building Translate on GlassBuilding Translate on Glass
Building Translate on Glass
 

Mais de Takuya Ueda

Goにおけるバージョン管理の必要性 − vgoについて −
Goにおけるバージョン管理の必要性 − vgoについて −Goにおけるバージョン管理の必要性 − vgoについて −
Goにおけるバージョン管理の必要性 − vgoについて −Takuya Ueda
 
WebAssembly with Go
WebAssembly with GoWebAssembly with Go
WebAssembly with GoTakuya Ueda
 
GAE/Goとsyncパッケージ
GAE/GoとsyncパッケージGAE/Goとsyncパッケージ
GAE/GoとsyncパッケージTakuya Ueda
 
静的解析を使った開発ツールの開発
静的解析を使った開発ツールの開発静的解析を使った開発ツールの開発
静的解析を使った開発ツールの開発Takuya Ueda
 
そうだ、Goを始めよう
そうだ、Goを始めようそうだ、Goを始めよう
そうだ、Goを始めようTakuya Ueda
 
マスター・オブ・goパッケージ
マスター・オブ・goパッケージマスター・オブ・goパッケージ
マスター・オブ・goパッケージTakuya Ueda
 
メルカリ カウルのマスタデータの更新
メルカリ カウルのマスタデータの更新メルカリ カウルのマスタデータの更新
メルカリ カウルのマスタデータの更新Takuya Ueda
 
Go Friday 傑作選
Go Friday 傑作選Go Friday 傑作選
Go Friday 傑作選Takuya Ueda
 
エキスパートGo
エキスパートGoエキスパートGo
エキスパートGoTakuya Ueda
 
Gopher Fest 2017参加レポート
Gopher Fest 2017参加レポートGopher Fest 2017参加レポート
Gopher Fest 2017参加レポートTakuya Ueda
 
Goでかんたんソースコードの静的解析
Goでかんたんソースコードの静的解析Goでかんたんソースコードの静的解析
Goでかんたんソースコードの静的解析Takuya Ueda
 
Goでwebアプリを開発してみよう
Goでwebアプリを開発してみようGoでwebアプリを開発してみよう
Goでwebアプリを開発してみようTakuya Ueda
 
GAE/GoでWebアプリ開発入門
GAE/GoでWebアプリ開発入門GAE/GoでWebアプリ開発入門
GAE/GoでWebアプリ開発入門Takuya Ueda
 
GAE/GoでLINE Messaging API を使う
GAE/GoでLINE Messaging API を使うGAE/GoでLINE Messaging API を使う
GAE/GoでLINE Messaging API を使うTakuya Ueda
 
メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法
メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法
メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法Takuya Ueda
 

Mais de Takuya Ueda (15)

Goにおけるバージョン管理の必要性 − vgoについて −
Goにおけるバージョン管理の必要性 − vgoについて −Goにおけるバージョン管理の必要性 − vgoについて −
Goにおけるバージョン管理の必要性 − vgoについて −
 
WebAssembly with Go
WebAssembly with GoWebAssembly with Go
WebAssembly with Go
 
GAE/Goとsyncパッケージ
GAE/GoとsyncパッケージGAE/Goとsyncパッケージ
GAE/Goとsyncパッケージ
 
静的解析を使った開発ツールの開発
静的解析を使った開発ツールの開発静的解析を使った開発ツールの開発
静的解析を使った開発ツールの開発
 
そうだ、Goを始めよう
そうだ、Goを始めようそうだ、Goを始めよう
そうだ、Goを始めよう
 
マスター・オブ・goパッケージ
マスター・オブ・goパッケージマスター・オブ・goパッケージ
マスター・オブ・goパッケージ
 
メルカリ カウルのマスタデータの更新
メルカリ カウルのマスタデータの更新メルカリ カウルのマスタデータの更新
メルカリ カウルのマスタデータの更新
 
Go Friday 傑作選
Go Friday 傑作選Go Friday 傑作選
Go Friday 傑作選
 
エキスパートGo
エキスパートGoエキスパートGo
エキスパートGo
 
Gopher Fest 2017参加レポート
Gopher Fest 2017参加レポートGopher Fest 2017参加レポート
Gopher Fest 2017参加レポート
 
Goでかんたんソースコードの静的解析
Goでかんたんソースコードの静的解析Goでかんたんソースコードの静的解析
Goでかんたんソースコードの静的解析
 
Goでwebアプリを開発してみよう
Goでwebアプリを開発してみようGoでwebアプリを開発してみよう
Goでwebアプリを開発してみよう
 
GAE/GoでWebアプリ開発入門
GAE/GoでWebアプリ開発入門GAE/GoでWebアプリ開発入門
GAE/GoでWebアプリ開発入門
 
GAE/GoでLINE Messaging API を使う
GAE/GoでLINE Messaging API を使うGAE/GoでLINE Messaging API を使う
GAE/GoでLINE Messaging API を使う
 
メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法
メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法
メルカリアッテの実務で使えた、GAE/Goの開発を効率的にする方法
 

Último

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Mobile Apps by Pure Go with Reverse Binding

  • 1. Mobile Apps by Pure Go with Reverse Binding GopherCon India 22nd Feb. 2017 The Go gopher was designed by Renee French. The gopher stickers was made by Takuya Ueda. Licensed under the Creative Commons 3.0 Attributions license. Slide URL: https://goo.gl/OG55gT
  • 2. Slide URL: https://goo.gl/OG55gT Who am I? Mercari, Inc./Souzoh, Inc. Takuya Ueda twitter: @tenntenn ■ Communities Google Cloud Platform User Group (GCPUG) Tokyo Go Beginners in Tokyo, Japan golang.tokyo Go Conference in Tokyo, Japan ■ Works Developing Mercari Atte in GAE/Go 2
  • 3. Slide URL: https://goo.gl/OG55gT What is this talk about? ● The Basics of Go Mobile ○ Cross-compile / cgo for Android ○ What is Go Mobile? ○ SDK Apps and Native Apps ● Developing Android Apps in pure Go ○ gomobile bind ○ What is Reverse Bindings? ○ Use Platform APIs from Go 3
  • 4. Slide URL: https://goo.gl/OG55gT The Basics of Go Mobile 4
  • 5. Slide URL: https://goo.gl/OG55gT Cross-compile ● GOOS and GOARCH ○ Go can cross-compile ○ GOOS indicates target OS ○ GOARCH indicates target architecture 5 # Build for 32bit Windows $ GOOS=windows GOARCH=386 go build # Build for arm Linux $ GOOS=linux GOARCH=arm go build A linux/arm binary also works on android devices.
  • 6. Slide URL: https://goo.gl/OG55gT Web server on Android Device 6 Watch at Youtube Source Code Android Shell on Mac adb shell
  • 7. Slide URL: https://goo.gl/OG55gT cgo ● C codes into Go codes 7 import "unsafe" /* #include <stdio.h> #include <stdlib.h> void hello(char *s) { printf("Hello, %sn", s); } */ import "C" func main() { str := C.CString("GopherCon India") C.hello(str) C.free(unsafe.Pointer(str)) } Comments before import "C" would be built as C codes Call C’s function from Go code
  • 8. Slide URL: https://goo.gl/OG55gT cgo for Android ● cgo codes also can be cross-compiled 8 $ CGO_ENABLED=1 CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 go build -buildmode=pie hellocgo.go $ adb push hellocgo /data/local/tmp $ chmod 755 /data/local/tmp/hellocgo $ /data/local/tmp/hellocgo Hello, GopherCon India GOOS should be android when CGO_ENABLED is 1. Enable cgo at cross-compiling adb shell PC
  • 9. Slide URL: https://goo.gl/OG55gT buildmode ● Change output formats ○ archive, c-archive ■ build into C archive (.a file) ○ shared, c-shared ■ build into shared library (.so file) ○ plugin ■ bulid into Go Plugin (<= Go 1.8) ○ exe ■ build into executable file ○ pie ■ build into PIE style executable file 9 archive and shared ignore main package Go can build to .so files for Android
  • 10. Slide URL: https://goo.gl/OG55gT Go Mobile ● What is Go Mobile? ○ Go Mobile is a toolkit for Mobile Platform (Android and iOS) in Go. ● How Go Mobile works? ○ Go Mobile provides bindings of Android and iOS through cgo. 10 Go C Java Obj-C JNIcgo Android iOS
  • 11. Slide URL: https://goo.gl/OG55gT Go Mobile 11 https://github.com/golang/mobile
  • 12. Slide URL: https://goo.gl/OG55gT Installation ● Install gomobile comand ● Initialize the build tool chain ○ gomobile init initializes the build tool chain for mobile apps. 12 $ gomobile init -v $ ls $GOPATH/pkg/gomobile android_ndk_root pkg_android_amd64 pkg_android_arm64 pkg_darwin_arm version pkg_android_386 pkg_android_arm pkg_darwin_amd64 pkg_darwin_arm64 $ go get -u golang.org/x/mobile/cmd/gomobile
  • 13. Slide URL: https://goo.gl/OG55gT gomobile command gomobile command provides sub-commands. ● Sub-commands 13 bind build a library for Android and iOS build compile Android APK and iOS app clean remove object files and cached gomobile files init install android compiler toolchain install compile android APK and install on device version print version
  • 14. Slide URL: https://goo.gl/OG55gT SDK Apps and Native Apps Go Mobile provides two ways to develop mobile apps. ■ SDK Apps ● Write common funcations in Go as a library ■ Native Apps ● Write UI and all codes in Go 14
  • 15. Slide URL: https://goo.gl/OG55gT SDK Apps and Native Apps ● SDK Apps for Android ● Native Apps for Android 15 Go aar file Binding Classes (Java) Shared library (.so) Java UI, IAB, ... As a library gomobile bind apk file Go GoNativeActivity Shared library (.so)UI, audio, ... gomobile build
  • 16. Slide URL: https://goo.gl/OG55gT An Example of SDK Apps: Ivy ● Ivy big number calculator (source code) ○ Interpriter for APL-like language ○ Android App and iOS App use a same engine ○ The engine is written in Go by Rob Pike 16 Google Play App Store
  • 17. Slide URL: https://goo.gl/OG55gT An Example of Native Apps ● Flappy Gopher ○ A mobile game written in Go Mobile ○ Developed by Andrew Gerrand for Go Conference 2015 Winter ○ Source Code 17
  • 18. Slide URL: https://goo.gl/OG55gT Developing Android Apps in Pure Go 18
  • 19. Slide URL: https://goo.gl/OG55gT gomobile bind ● Generate an Android Archive (.aar) ○ a shared library (.so) written in Go ○ a JAR file which is bult Java bindings ● Develop with Android Studio Plugin ○ Runs gomobile bind ○ Links to a generated .aar file 19 $ gomobile bind [-target ios|android] mypkg
  • 20. Slide URL: https://goo.gl/OG55gT Contents of an AAR file 20 $ gomobile bind sample $ unzip -Z1 sample.aar AndroidManifest.xml proguard.txt classes.jar jni/armeabi-v7a/libgojni.so jni/arm64-v8a/libgojni.so jni/x86/libgojni.so jni/x86_64/libgojni.so R.txt res/ Compiled Java codes Compiled Go/C codes
  • 21. Slide URL: https://goo.gl/OG55gT Calling Go code from Java code 21 Bindings Java codes Application Codes (Java) C codes Go/cgo codes JNI Generated by gomobile bind SDK Codes (Go) cgo
  • 22. Slide URL: https://goo.gl/OG55gT An Example of Bindings 22 package sample func Hello() string { return "Hello" } type MyStruct struct { Str string } func (s MyStruct) MyMethod() string { return s.Str } public abstract class Sample { // ... private Sample() {} // uninstantiable public static final class MyStruct extends Seq.Proxy { public final native String getStr(); public final native void setStr(String v); public native String MyMethod(); // ... } public static native String Hello(); } Java Go Struct Field Method Package Function
  • 23. Slide URL: https://goo.gl/OG55gT Type restrictions ● Signed integer and floating point type ● String and boolean type ● Byte slice type ● Any functions ○ parameter and result types must be supported types ○ results are 0, 1 or 2 (2nd result must be an error type) ● Any struct type ○ all fields and methods must be supported types ● Any interface ○ all methods must be supported types 23
  • 24. Slide URL: https://goo.gl/OG55gT Calling Platform API from Go ● In-app Billing ○ Purchase a items in the game ● SNS connection ○ Facebook, Twitter, ... ● Advertisements ● Analytics ○ Google Analytics, Firebase, Facebook Analytics,... 24 These APIs are provided as Java SDK for Android
  • 25. Slide URL: https://goo.gl/OG55gT Traditional gomobile bind ● Bindings to Go from Java/Obj-C ● Platform APIs can be accessed BUT... ○ Indirect way ○ Needs wrappers ○ Not convenient 25 A way to access directly Platform APIs from Go is needed!
  • 26. Slide URL: https://goo.gl/OG55gT Reverse Bindings ● Access Platform APIs from Go ● Generate bindings automatically ○ Reverse direction of traditional one ○ use gomobile bind ● Prposed by #16876 and #17102 (Android) (iOS) 26
  • 27. Slide URL: https://goo.gl/OG55gT Reverse Bindings 27 Bindings Java codes Go Codes C codes Go/cgo codes JNI Generated by gomobile bind Platform APIs (Java) cgo
  • 28. Slide URL: https://goo.gl/OG55gT An Example of Reverse Bindings 28 package pkg import "Java/java/lang" import "Java/pkg" type Obj struct { lang.Object } func (h *Obj) ToString(this *pkg.Obj) string { return "hoge" } ● Parse import statements ○ Java/* or ObjC/* ● Generate bindings automatically corresponds java.lang package in Java inherit java.lang.Object Hold a Java instance
  • 29. Slide URL: https://goo.gl/OG55gT How Generate Reverse Bindings? ● Parse import statements ○ Begin with Java/ ● Extract class infomation by javap ○ Exported fields and methods ○ Dependent classes ○ Implementing interfaces ● Generate bindings of all dependented classes and interfaces 29 $ javap java.lang.String Compiled from "String.java" public final class java.lang.String implements java.io.Serializable, java.lang.Comparable<java.lang.String>, java.lang.CharSequence { public static final java.util.Comparator<java.lang.String> CASE_INSENSITIVE_ORDER; public java.lang.String(); ....
  • 30. Slide URL: https://goo.gl/OG55gT Using Platform APIs from Go ● Example of Reverse Binding in x/mobile 30 $ cd $GOPATH/src/golang.org/x/mobile $ cd example/reverse/android $ gradle wrapper $ ./gradlew build $ cd build/outputs/apk $ adb install -r android-debug.apk Android Studio also can build
  • 31. Slide URL: https://goo.gl/OG55gT Use Platform APIs from Go ● Use Activity and write in life cycle of Android 31 type MainActivity struct { app.AppCompatActivity binding databinding.ActivityMainBinding } func (a *MainActivity) OnCreate( this gopkg.MainActivity, b os.Bundle) { ... } func (a *MainActivity) OnDestroy( this gopkg.MainActivity) { ... } reverse.go
  • 32. Slide URL: https://goo.gl/OG55gT Use Platform APIs from Go ● Use data binding of Android 32 func (a *MainActivity) OnCreate( this gopkg.MainActivity, b os.Bundle) { this.Super().OnCreate(b) db := DataBindingUtil.SetContentView( this, rlayout.Activity_main) a.binding = ActivityMainBinding.Cast(db) a.binding.SetAct(this) } func (a *MainActivity) GetLabel() string { return "Hello, GopherCon India!" } reverse.go
  • 33. Slide URL: https://goo.gl/OG55gT Use Platform APIs from Go ● Use data binding of Android 33 ... <data> <variable name="act" type="reverse.MainActivity"/> </data> <RelativeLayout ... <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{act.label}"/> </RelativeLayout> </layout> activity_main.xml
  • 34. Slide URL: https://goo.gl/OG55gT Summaries ● The Basics of Go Mobile ○ Cross-compile / cgo for Android ○ What is Go Mobile? ○ SDK Apps and Native Apps ● Developing Android Apps in pure Go ○ gomobile bind ○ What is Reverse Bindings? ○ Use Platform APIs from Go 34
  • 36. Slide URL: https://goo.gl/OG55gT Binding between Go and Java 36 Package Abstruct Class Struct Inner Class Struct Field Getter/Setter (Native) Method Method (Native) Package Function Static Method Go Java ● gomobile bind generates bindings