SlideShare a Scribd company logo
HelloAndroid.go
SeongJae Park <sj38.park@gmail.com>
This work by SeongJae Park is licensed under the Creative
Commons Attribution-ShareAlike 3.0 Unported License. To
view a copy of this license, visit http://creativecommons.
org/licenses/by-sa/3.0/.
This slides were presented during
3rd GDG Korea Android Conference
(http://event.android.gdg.kr/3rd-GKAC/)
The talk video is available at:
https://www.youtube.com/watch?v=vMZFjDipaK8&index=2&list=PL_WJkTbDHdBl5QXy6N_bMMBYlKLna5RER
Nice To Meet You
SeongJae Park
sj38.park@gmail.com
golang newbie programmer
Warning
● This speech could be useless for you
○ This is just for fun
http://m.c.lnkd.licdn.com/mpr/mpr/p/4/005/095/091/210ae8c.jpg
Warning
● This speech could be useless for you
○ This is just for fun
● Don’t try this at office
○ The code is not stable yet
http://m.c.lnkd.licdn.com/mpr/mpr/p/4/005/095/091/210ae8c.jpg
golang: Programming Language
● For simple, reliable, and efficient software.
http://blog.golang.org/5years/gophers5th.jpg
golang: Programming Language
● For simple, reliable, and efficient software.
● Could it be used for simple, reliable, and
efficient Android application?
http://blog.golang.org/5years/gophers5th.jpg
Golang and Android
● Golang supports Android from v1.4
○ Though it’s still unstable
Golang and Android
● Golang supports Android from v1.4
○ Though it’s still unstable
● https://github.com/golang/mobile
○ Packages and build tools for using Go on Android
Goal of This Speak
● Showing how we can use golang on Android
○ By exploring example code
Goal of This Speak
● Showing how we can use golang on Android
○ By exploring example code
● Just for fun, rather than profit
Pre-requisites
● Basic development environment(vim, git,
gcc, java, …)
http://www.theprospect.net/wp-content/uploads/2014/02/one-does-not-simply-skip-a-step.jpg
Pre-requisites
● Basic development environment(vim, git,
gcc, java, …)
● Android SDK & NDK
http://www.theprospect.net/wp-content/uploads/2014/02/one-does-not-simply-skip-a-step.jpg
Pre-requisites
● Basic development environment(vim, git,
gcc, java, …)
● Android SDK & NDK
● Golang 1.4 or higher cross-compiled for
GOOS=android
http://www.theprospect.net/wp-content/uploads/2014/02/one-does-not-simply-skip-a-step.jpg
Pure Golang Android App
NO JAVA!
Main Idea: Use NDK
● c / c++ only apk is available
using NativeActivity
○ Golang be compiled to native binary, too. Why not?
http://www.android.pk/images/android-ndk.jpg
Main Idea: Use NDK
● c / c++ only apk is available
using NativeActivity
○ Golang be compiled to native binary, too. Why not?
Plan is...
● Build golang program as .so file
○ ELF shared object
● Implement every callbacks using OpenGL
http://www.android.pk/images/android-ndk.jpg
Main Idea: Use NDK
● c / c++ only apk is available
using NativeActivity
○ Golang be compiled to native binary, too. Why not?
Plan is...
● Build golang program as .so file
○ ELF shared object
● Implement every callbacks using OpenGL
● Build NativeActivity apk using NDK / SDK
http://www.android.pk/images/android-ndk.jpg
Example Code
https://github.
com/golang/mobile/tree/master/example/basic
Example Code
https://github.
com/golang/mobile/tree/master/example/basic
$ tree
.
├── all.bash
├── all.bat
├── AndroidManifest.xml
├── build.xml
├── jni
│ └── Android.mk
├── main.go
├── make.bash
└── make.bat
1 directory, 8 files
main.go: Register Callbacks
Register callbacks from golang entrypoint
func main() {
app.Run(app.Callbacks{
Start: start,
Stop: stop,
Draw: draw,
Touch: touch,
})
}
(mobile/example/basic/main.go)
main.go: Use OpenGL
func draw() {
gl.ClearColor(1, 0, 0, 1)
...
green += 0.01
if green > 1 {
green = 0
}
gl.Uniform4f(color, 0, green, 0, 1)
...
debug.DrawFPS()
}
(mobile/example/basic/main.go)
NativeActivity
NativeActivity only application doesn’t need
JAVA
<application android:label="Basic" android:hasCode="false">
<activity android:name="android.app.NativeActivity"
android:label="Basic"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="basic" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
(mobile/example/basic/AndroidManifest.xml)
NativeActivity
NativeActivity only application doesn’t need
JAVA
<application android:label="Basic" android:hasCode="false">
<activity android:name="android.app.NativeActivity"
android:label="Basic"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="basic" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
(mobile/example/basic/AndroidManifest.xml)
NativeActivity
NativeActivity only application doesn’t need
JAVA
<application android:label="Basic" android:hasCode="false">
<activity android:name="android.app.NativeActivity"
android:label="Basic"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="basic" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
(mobile/example/basic/AndroidManifest.xml)
Build Process
Build golang code into ELF shared object for
ARM
mkdir -p jni/armeabi
CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 
go build -ldflags="-shared" -o jni/armeabi/libbasic.so .
ndk-build NDK_DEBUG=1
ant debug
(mobile/example/basic/make.bash)
Build Process
Build golang code into ELF shared object for
ARM
NDK to add the so file
mkdir -p jni/armeabi
CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 
go build -ldflags="-shared" -o jni/armeabi/libbasic.so .
ndk-build NDK_DEBUG=1
ant debug
(mobile/example/basic/make.bash)
Build Process
Build golang code into ELF shared object for
ARM
NDK to add the so file
SDK to build apk file
mkdir -p jni/armeabi
CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 
go build -ldflags="-shared" -o jni/armeabi/libbasic.so .
ndk-build NDK_DEBUG=1
ant debug
(mobile/example/basic/make.bash)
Pure Golang Android App
Pros: No more JAVA! Yay!!!
Cons: Should I learn OpenGL to show a cat?
Golang as a Library
Cooperate Java and Golang
Java and C language connected via JNI
Main Idea: Use JNI-like way
Java
CPP
JNI
Main Idea: Use JNI-like way
Java and C language connected via JNI
C language and Golang connected via cgo
Java
CPP
GO
JNI CGO
Main Idea: Use JNI-like way
Java and C language connected via JNI
C language and Golang connected via cgo
...But, JNI and then cgo looks tedious
Java
CPP
GO
JNI CGO
Main Idea: Use JNI-like way
Java and C language connected via JNI
C language and Golang connected via cgo
...But, JNI and then cgo looks tedious
Golang supports Java-Golang bind
Java
CPP
GO
JNI CGO
bind/seq
Example Code
https://github.
com/golang/mobile/tree/
master/example/libhello
Example Code
https://github.
com/golang/mobile/tree/
master/example/libhello
$ tree
.
├── all.bash
├── all.bat
├── AndroidManifest.xml
├── build.xml
├── hi
│ ├── go_hi
│ │ └── go_hi.go
│ └── hi.go
├── main.go
├── make.bash
├── make.bat
├── README
└── src
├── com
│ └── example
│ └── hello
│ └── MainActivity.java
└── go
└── hi
└── Hi.java
8 directories, 12 files
Callee in Go
Golang code is implementing Hello() function
func Hello(name string) {
fmt.Printf("Hello, %s!n", name)
}
(mobile/example/libhello/hi/hi.go)
Caller in JAVA
Java code is calling Golang function, Hello()
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Go.init(getApplicationContext());
Hi.Hello("world");
}
(mobile/example/libhello/src/com/example/hello/MainActivity.java)
gobind
generate language bindings that make it
possible to call Go code and pass objects from
Java
go install golang.org/x/mobile/cmd/gobind
gobind -lang=go github.com/libhello/hi > hi/go_hi/go_hi.go
gobind -lang=java github.com/libhello/hi > src/go/hi/Hi.java
gobind: Generated .java
Provides wrapper function for golang calling
code
public static void Hello(String name) {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
_in.writeUTF16(name);
Seq.send(DESCRIPTOR, CALL_Hello, _in, _out);
}
private static final int CALL_Hello = 1;
private static final String DESCRIPTOR = "hi";
(mobile/example/libhello/src/go/hi/Hi.java)
gobind: Generated .go
Provides proxy and registering for the exported
function
func proxy_Hello(out, in *seq.Buffer) {
param_name := in.ReadUTF16()
hi.Hello(param_name)
}
func init() {
seq.Register("hi", 1, proxy_Hello)
}
(mobile/example/libhello/hi/go_hi/go_hi.go)
Golang as a Library
Pros: JAVA for UI, Golang for background
(Looks efficient enough)
Golang as a Library
Pros: JAVA for UI, Golang for background
(Looks efficient enough)
Cons: bind/seq is not so efficient, yet
Inter-Process
Communication
Philosophy of Unix
Main Idea: Android is a Linux
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
Android is a variant of Linux system with ARM
x86 Androids exist, though...
Main Idea: Android is a Linux
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
Android is a variant of Linux system with ARM
x86 Androids exist, though...
Go supports ARM & Linux Officially
with static-linking
Main Idea: Android is a Linux
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
Android is a variant of Linux system with ARM
x86 Androids exist, though...
Go supports ARM & Linux Officially
with static-linking
Remember the philosophy of Unix
Example Code
https://github.com/sjp38/goOnAndroid
https://github.com/sjp38/goOnAndroidFA
Example Code
https://github.com/sjp38/goOnAndroid
https://github.com/sjp38/goOnAndroidFA
Were demonstrated by live-coding from
GDG Korea DevFair 2014 (http://devfair2014.
gdg.kr/) and
GDG Golang Seoul Meetup 2015 (https:
//developers.google.
com/events/5381849181323264/)
Golang Process on Android: Plan
1. Cross compile Go program as ARM / Linux
Golang Process on Android: Plan
1. Cross compile Go program as ARM / Linux
2. Include the binary in assets/ of Android app
Golang Process on Android: Plan
1. Cross compile Go program as ARM / Linux
2. Include the binary in assets/ of Android app
3. Copy the binary in private space of the app
Golang Process on Android: Plan
1. Cross compile Go program as ARM / Linux
2. Include the binary in assets/ of Android app
3. Copy the binary in private space of the app
4. Give execute permission to the binary
/data/data/com.example.goRunner/files # ls -al
-rwxrwxrwx u0_a55 u0_a55 4512840 2014-11-28 17:45 gobin
Golang Process on Android: Plan
1. Cross compile Go program as ARM / Linux
2. Include the binary in assets/ of Android app
3. Copy the binary in private space of the app
4. Give execute permission to the binary
5. Execute it
/data/data/com.example.goRunner/files # ls -al
-rwxrwxrwx u0_a55 u0_a55 4512840 2014-11-28 17:45 gobin
Go bin Loading
Load golang program from assets to private dir
private void copyGoBinary() {
String dstFile = getBaseContext().getFilesDir().getAbsolutePath() + "/verChecker.bin";
try {
InputStream is = getAssets().open("go.bin");
FileOutputStream fos = getBaseContext().openFileOutput(
"verChecker.bin", MODE_PRIVATE);
byte[] buf = new byte[8192];
int offset;
while ((offset = is.read(buf)) > 0) {
fos.write(buf, 0, offset);
}
Runtime.getRuntime().exec("chmod 0777 " + dstFile);
} catch (IOException e) { }
}
Execute Go process
Spawn new process for the program and
communicates using stdio
ProcessBuilder pb = new ProcessBuilder();
pb.command(goBinPath());
pb.redirectErrorStream(false);
goProcess = pb.start();
new CopyToAndroidLogThread("stderr",
goProcess.getErrorStream())
.start();
Inter Process Communication
Pros: Just normal unix way
Inter Process Communication
Pros: Just normal unix way
Golang team is using this for Camlistore
(https://github.com/camlistore/camlistore)
Inter Process Communication
Pros: Just normal unix way
Golang team using this for Camlistore
(https://github.com/camlistore/camlistore)
Cons: Hacky, a little
Summary
You can use Golang for Android
though it’s not stable yet
Just for fun
This work by SeongJae Park is licensed under the
Creative Commons Attribution-ShareAlike 3.0 Unported
License. To view a copy of this license, visit http:
//creativecommons.org/licenses/by-sa/3.0/.

More Related Content

What's hot

BDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVABDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVA
Srinivas Katakam
 
Testes em todos os niveis de planejamento
Testes em todos os niveis de planejamentoTestes em todos os niveis de planejamento
Testes em todos os niveis de planejamento
Elias Nogueira
 
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler WebinarKeycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
marcuschristie
 
Successfully Implementing BDD in an Agile World
Successfully Implementing BDD in an Agile WorldSuccessfully Implementing BDD in an Agile World
Successfully Implementing BDD in an Agile World
SmartBear
 
API Test Automation using Karate.pdf
API Test Automation using Karate.pdfAPI Test Automation using Karate.pdf
API Test Automation using Karate.pdf
Venessa Serrao
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
Roman Liubun
 
Android volley
Android volleyAndroid volley
Android volley
Programming Talents
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
M. Raihan
 
Code Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoCode Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoEvgeny Mandrikov
 
Code coverage
Code coverageCode coverage
Code coverage
Return on Intelligence
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
intuit_india
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
VMware Tanzu
 
Code Coverage
Code CoverageCode Coverage
Code Coverage
Ernani Omar Cruz
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
Sergey Pichkurov
 
Gherkin /BDD intro
Gherkin /BDD introGherkin /BDD intro
Azure DevOps Tests Plan
Azure DevOps Tests PlanAzure DevOps Tests Plan
Azure DevOps Tests Plan
Denis Voituron
 

What's hot (20)

Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
BDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVABDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVA
 
Testes em todos os niveis de planejamento
Testes em todos os niveis de planejamentoTestes em todos os niveis de planejamento
Testes em todos os niveis de planejamento
 
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler WebinarKeycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
 
Successfully Implementing BDD in an Agile World
Successfully Implementing BDD in an Agile WorldSuccessfully Implementing BDD in an Agile World
Successfully Implementing BDD in an Agile World
 
API Test Automation using Karate.pdf
API Test Automation using Karate.pdfAPI Test Automation using Karate.pdf
API Test Automation using Karate.pdf
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
Android volley
Android volleyAndroid volley
Android volley
 
Software Testing 4/5
Software Testing 4/5Software Testing 4/5
Software Testing 4/5
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
 
Code Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoCode Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCo
 
Code coverage
Code coverageCode coverage
Code coverage
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
 
Code Coverage
Code CoverageCode Coverage
Code Coverage
 
Testes Unitários usando TestNG
Testes Unitários usando TestNGTestes Unitários usando TestNG
Testes Unitários usando TestNG
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
Gherkin /BDD intro
Gherkin /BDD introGherkin /BDD intro
Gherkin /BDD intro
 
Azure DevOps Tests Plan
Azure DevOps Tests PlanAzure DevOps Tests Plan
Azure DevOps Tests Plan
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 

Similar to Develop Android app using Golang

Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golang
SeongJae Park
 
Go for Mobile Games
Go for Mobile GamesGo for Mobile Games
Go for Mobile Games
Takuya Ueda
 
Mobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse BindingMobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse Binding
Takuya Ueda
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
Marcin Pasinski
 
How to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDKHow to Build & Use OpenCL on OpenCV & Android NDK
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
Bo-Yi Wu
 
Optimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerOptimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for Docker
Graham Charters
 
(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
SeongJae Park
 
JLPDevs - Optimization Tooling for Modern Web App Development
JLPDevs - Optimization Tooling for Modern Web App DevelopmentJLPDevs - Optimization Tooling for Modern Web App Development
JLPDevs - Optimization Tooling for Modern Web App Development
JLP Community
 
Metasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDKMetasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDK
Kiwamu Okabe
 
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
SeongJae Park
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
Abraham Aranguren
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
Bogusz Jelinski
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
Nick Plante
 
Drone sdk showdown
Drone sdk showdownDrone sdk showdown
Drone sdk showdown
Godfrey Nolan
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
KAI CHU CHUNG
 
Introduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google CloudIntroduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google Cloud
wesley chun
 
A Noob’S Guide To Android Application Development
A Noob’S Guide To Android Application DevelopmentA Noob’S Guide To Android Application Development
A Noob’S Guide To Android Application Development
Zi Yong Chua
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
KAI CHU CHUNG
 
Multi-stage Docker builds to make building easy!
Multi-stage Docker builds to make building easy!Multi-stage Docker builds to make building easy!
Multi-stage Docker builds to make building easy!
Milindu Sanoj Kumarage
 

Similar to Develop Android app using Golang (20)

Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golang
 
Go for Mobile Games
Go for Mobile GamesGo for Mobile Games
Go for Mobile Games
 
Mobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse BindingMobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse Binding
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
How to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDKHow to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDK
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Optimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerOptimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for Docker
 
(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
 
JLPDevs - Optimization Tooling for Modern Web App Development
JLPDevs - Optimization Tooling for Modern Web App DevelopmentJLPDevs - Optimization Tooling for Modern Web App Development
JLPDevs - Optimization Tooling for Modern Web App Development
 
Metasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDKMetasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDK
 
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
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Drone sdk showdown
Drone sdk showdownDrone sdk showdown
Drone sdk showdown
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
 
Introduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google CloudIntroduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google Cloud
 
A Noob’S Guide To Android Application Development
A Noob’S Guide To Android Application DevelopmentA Noob’S Guide To Android Application Development
A Noob’S Guide To Android Application Development
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
 
Multi-stage Docker builds to make building easy!
Multi-stage Docker builds to make building easy!Multi-stage Docker builds to make building easy!
Multi-stage Docker builds to make building easy!
 

More from SeongJae Park

Biscuit: an operating system written in go
Biscuit:  an operating system written in goBiscuit:  an operating system written in go
Biscuit: an operating system written in go
SeongJae Park
 
GCMA: Guaranteed Contiguous Memory Allocator
GCMA: Guaranteed Contiguous Memory AllocatorGCMA: Guaranteed Contiguous Memory Allocator
GCMA: Guaranteed Contiguous Memory Allocator
SeongJae Park
 
Linux Kernel Memory Model
Linux Kernel Memory ModelLinux Kernel Memory Model
Linux Kernel Memory Model
SeongJae Park
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux Kernel
SeongJae Park
 
Design choices of golang for high scalability
Design choices of golang for high scalabilityDesign choices of golang for high scalability
Design choices of golang for high scalability
SeongJae Park
 
Brief introduction to kselftest
Brief introduction to kselftestBrief introduction to kselftest
Brief introduction to kselftest
SeongJae Park
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory model
SeongJae Park
 
Let the contribution begin (EST futures)
Let the contribution begin  (EST futures)Let the contribution begin  (EST futures)
Let the contribution begin (EST futures)
SeongJae Park
 
gcma: guaranteed contiguous memory allocator
gcma:  guaranteed contiguous memory allocatorgcma:  guaranteed contiguous memory allocator
gcma: guaranteed contiguous memory allocator
SeongJae Park
 
An introduction to_golang.avi
An introduction to_golang.aviAn introduction to_golang.avi
An introduction to_golang.avi
SeongJae Park
 
Sw install with_without_docker
Sw install with_without_dockerSw install with_without_docker
Sw install with_without_docker
SeongJae Park
 
Git inter-snapshot public
Git  inter-snapshot publicGit  inter-snapshot public
Git inter-snapshot public
SeongJae Park
 
Deep dark-side of git: How git works internally
Deep dark-side of git: How git works internallyDeep dark-side of git: How git works internally
Deep dark-side of git: How git works internally
SeongJae Park
 
Deep dark side of git - prologue
Deep dark side of git - prologueDeep dark side of git - prologue
Deep dark side of git - prologueSeongJae Park
 
DO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCSDO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCS
SeongJae Park
 
Experimental android hacking using reflection
Experimental android hacking using reflectionExperimental android hacking using reflection
Experimental android hacking using reflection
SeongJae Park
 
ash
ashash
Hacktime for adk
Hacktime for adkHacktime for adk
Hacktime for adk
SeongJae Park
 
Let the contribution begin
Let the contribution beginLet the contribution begin
Let the contribution begin
SeongJae Park
 
Touch Android Without Touching
Touch Android Without TouchingTouch Android Without Touching
Touch Android Without Touching
SeongJae Park
 

More from SeongJae Park (20)

Biscuit: an operating system written in go
Biscuit:  an operating system written in goBiscuit:  an operating system written in go
Biscuit: an operating system written in go
 
GCMA: Guaranteed Contiguous Memory Allocator
GCMA: Guaranteed Contiguous Memory AllocatorGCMA: Guaranteed Contiguous Memory Allocator
GCMA: Guaranteed Contiguous Memory Allocator
 
Linux Kernel Memory Model
Linux Kernel Memory ModelLinux Kernel Memory Model
Linux Kernel Memory Model
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux Kernel
 
Design choices of golang for high scalability
Design choices of golang for high scalabilityDesign choices of golang for high scalability
Design choices of golang for high scalability
 
Brief introduction to kselftest
Brief introduction to kselftestBrief introduction to kselftest
Brief introduction to kselftest
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory model
 
Let the contribution begin (EST futures)
Let the contribution begin  (EST futures)Let the contribution begin  (EST futures)
Let the contribution begin (EST futures)
 
gcma: guaranteed contiguous memory allocator
gcma:  guaranteed contiguous memory allocatorgcma:  guaranteed contiguous memory allocator
gcma: guaranteed contiguous memory allocator
 
An introduction to_golang.avi
An introduction to_golang.aviAn introduction to_golang.avi
An introduction to_golang.avi
 
Sw install with_without_docker
Sw install with_without_dockerSw install with_without_docker
Sw install with_without_docker
 
Git inter-snapshot public
Git  inter-snapshot publicGit  inter-snapshot public
Git inter-snapshot public
 
Deep dark-side of git: How git works internally
Deep dark-side of git: How git works internallyDeep dark-side of git: How git works internally
Deep dark-side of git: How git works internally
 
Deep dark side of git - prologue
Deep dark side of git - prologueDeep dark side of git - prologue
Deep dark side of git - prologue
 
DO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCSDO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCS
 
Experimental android hacking using reflection
Experimental android hacking using reflectionExperimental android hacking using reflection
Experimental android hacking using reflection
 
ash
ashash
ash
 
Hacktime for adk
Hacktime for adkHacktime for adk
Hacktime for adk
 
Let the contribution begin
Let the contribution beginLet the contribution begin
Let the contribution begin
 
Touch Android Without Touching
Touch Android Without TouchingTouch Android Without Touching
Touch Android Without Touching
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Develop Android app using Golang

  • 2. This work by SeongJae Park is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons. org/licenses/by-sa/3.0/.
  • 3. This slides were presented during 3rd GDG Korea Android Conference (http://event.android.gdg.kr/3rd-GKAC/) The talk video is available at: https://www.youtube.com/watch?v=vMZFjDipaK8&index=2&list=PL_WJkTbDHdBl5QXy6N_bMMBYlKLna5RER
  • 4. Nice To Meet You SeongJae Park sj38.park@gmail.com golang newbie programmer
  • 5. Warning ● This speech could be useless for you ○ This is just for fun http://m.c.lnkd.licdn.com/mpr/mpr/p/4/005/095/091/210ae8c.jpg
  • 6. Warning ● This speech could be useless for you ○ This is just for fun ● Don’t try this at office ○ The code is not stable yet http://m.c.lnkd.licdn.com/mpr/mpr/p/4/005/095/091/210ae8c.jpg
  • 7. golang: Programming Language ● For simple, reliable, and efficient software. http://blog.golang.org/5years/gophers5th.jpg
  • 8. golang: Programming Language ● For simple, reliable, and efficient software. ● Could it be used for simple, reliable, and efficient Android application? http://blog.golang.org/5years/gophers5th.jpg
  • 9. Golang and Android ● Golang supports Android from v1.4 ○ Though it’s still unstable
  • 10. Golang and Android ● Golang supports Android from v1.4 ○ Though it’s still unstable ● https://github.com/golang/mobile ○ Packages and build tools for using Go on Android
  • 11. Goal of This Speak ● Showing how we can use golang on Android ○ By exploring example code
  • 12. Goal of This Speak ● Showing how we can use golang on Android ○ By exploring example code ● Just for fun, rather than profit
  • 13. Pre-requisites ● Basic development environment(vim, git, gcc, java, …) http://www.theprospect.net/wp-content/uploads/2014/02/one-does-not-simply-skip-a-step.jpg
  • 14. Pre-requisites ● Basic development environment(vim, git, gcc, java, …) ● Android SDK & NDK http://www.theprospect.net/wp-content/uploads/2014/02/one-does-not-simply-skip-a-step.jpg
  • 15. Pre-requisites ● Basic development environment(vim, git, gcc, java, …) ● Android SDK & NDK ● Golang 1.4 or higher cross-compiled for GOOS=android http://www.theprospect.net/wp-content/uploads/2014/02/one-does-not-simply-skip-a-step.jpg
  • 16. Pure Golang Android App NO JAVA!
  • 17. Main Idea: Use NDK ● c / c++ only apk is available using NativeActivity ○ Golang be compiled to native binary, too. Why not? http://www.android.pk/images/android-ndk.jpg
  • 18. Main Idea: Use NDK ● c / c++ only apk is available using NativeActivity ○ Golang be compiled to native binary, too. Why not? Plan is... ● Build golang program as .so file ○ ELF shared object ● Implement every callbacks using OpenGL http://www.android.pk/images/android-ndk.jpg
  • 19. Main Idea: Use NDK ● c / c++ only apk is available using NativeActivity ○ Golang be compiled to native binary, too. Why not? Plan is... ● Build golang program as .so file ○ ELF shared object ● Implement every callbacks using OpenGL ● Build NativeActivity apk using NDK / SDK http://www.android.pk/images/android-ndk.jpg
  • 21. Example Code https://github. com/golang/mobile/tree/master/example/basic $ tree . ├── all.bash ├── all.bat ├── AndroidManifest.xml ├── build.xml ├── jni │ └── Android.mk ├── main.go ├── make.bash └── make.bat 1 directory, 8 files
  • 22. main.go: Register Callbacks Register callbacks from golang entrypoint func main() { app.Run(app.Callbacks{ Start: start, Stop: stop, Draw: draw, Touch: touch, }) } (mobile/example/basic/main.go)
  • 23. main.go: Use OpenGL func draw() { gl.ClearColor(1, 0, 0, 1) ... green += 0.01 if green > 1 { green = 0 } gl.Uniform4f(color, 0, green, 0, 1) ... debug.DrawFPS() } (mobile/example/basic/main.go)
  • 24. NativeActivity NativeActivity only application doesn’t need JAVA <application android:label="Basic" android:hasCode="false"> <activity android:name="android.app.NativeActivity" android:label="Basic" android:configChanges="orientation|keyboardHidden"> <meta-data android:name="android.app.lib_name" android:value="basic" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> (mobile/example/basic/AndroidManifest.xml)
  • 25. NativeActivity NativeActivity only application doesn’t need JAVA <application android:label="Basic" android:hasCode="false"> <activity android:name="android.app.NativeActivity" android:label="Basic" android:configChanges="orientation|keyboardHidden"> <meta-data android:name="android.app.lib_name" android:value="basic" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> (mobile/example/basic/AndroidManifest.xml)
  • 26. NativeActivity NativeActivity only application doesn’t need JAVA <application android:label="Basic" android:hasCode="false"> <activity android:name="android.app.NativeActivity" android:label="Basic" android:configChanges="orientation|keyboardHidden"> <meta-data android:name="android.app.lib_name" android:value="basic" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> (mobile/example/basic/AndroidManifest.xml)
  • 27. Build Process Build golang code into ELF shared object for ARM mkdir -p jni/armeabi CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-shared" -o jni/armeabi/libbasic.so . ndk-build NDK_DEBUG=1 ant debug (mobile/example/basic/make.bash)
  • 28. Build Process Build golang code into ELF shared object for ARM NDK to add the so file mkdir -p jni/armeabi CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-shared" -o jni/armeabi/libbasic.so . ndk-build NDK_DEBUG=1 ant debug (mobile/example/basic/make.bash)
  • 29. Build Process Build golang code into ELF shared object for ARM NDK to add the so file SDK to build apk file mkdir -p jni/armeabi CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-shared" -o jni/armeabi/libbasic.so . ndk-build NDK_DEBUG=1 ant debug (mobile/example/basic/make.bash)
  • 30. Pure Golang Android App Pros: No more JAVA! Yay!!! Cons: Should I learn OpenGL to show a cat?
  • 31. Golang as a Library Cooperate Java and Golang
  • 32. Java and C language connected via JNI Main Idea: Use JNI-like way Java CPP JNI
  • 33. Main Idea: Use JNI-like way Java and C language connected via JNI C language and Golang connected via cgo Java CPP GO JNI CGO
  • 34. Main Idea: Use JNI-like way Java and C language connected via JNI C language and Golang connected via cgo ...But, JNI and then cgo looks tedious Java CPP GO JNI CGO
  • 35. Main Idea: Use JNI-like way Java and C language connected via JNI C language and Golang connected via cgo ...But, JNI and then cgo looks tedious Golang supports Java-Golang bind Java CPP GO JNI CGO bind/seq
  • 37. Example Code https://github. com/golang/mobile/tree/ master/example/libhello $ tree . ├── all.bash ├── all.bat ├── AndroidManifest.xml ├── build.xml ├── hi │ ├── go_hi │ │ └── go_hi.go │ └── hi.go ├── main.go ├── make.bash ├── make.bat ├── README └── src ├── com │ └── example │ └── hello │ └── MainActivity.java └── go └── hi └── Hi.java 8 directories, 12 files
  • 38. Callee in Go Golang code is implementing Hello() function func Hello(name string) { fmt.Printf("Hello, %s!n", name) } (mobile/example/libhello/hi/hi.go)
  • 39. Caller in JAVA Java code is calling Golang function, Hello() protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Go.init(getApplicationContext()); Hi.Hello("world"); } (mobile/example/libhello/src/com/example/hello/MainActivity.java)
  • 40. gobind generate language bindings that make it possible to call Go code and pass objects from Java go install golang.org/x/mobile/cmd/gobind gobind -lang=go github.com/libhello/hi > hi/go_hi/go_hi.go gobind -lang=java github.com/libhello/hi > src/go/hi/Hi.java
  • 41. gobind: Generated .java Provides wrapper function for golang calling code public static void Hello(String name) { go.Seq _in = new go.Seq(); go.Seq _out = new go.Seq(); _in.writeUTF16(name); Seq.send(DESCRIPTOR, CALL_Hello, _in, _out); } private static final int CALL_Hello = 1; private static final String DESCRIPTOR = "hi"; (mobile/example/libhello/src/go/hi/Hi.java)
  • 42. gobind: Generated .go Provides proxy and registering for the exported function func proxy_Hello(out, in *seq.Buffer) { param_name := in.ReadUTF16() hi.Hello(param_name) } func init() { seq.Register("hi", 1, proxy_Hello) } (mobile/example/libhello/hi/go_hi/go_hi.go)
  • 43. Golang as a Library Pros: JAVA for UI, Golang for background (Looks efficient enough)
  • 44. Golang as a Library Pros: JAVA for UI, Golang for background (Looks efficient enough) Cons: bind/seq is not so efficient, yet
  • 46. Main Idea: Android is a Linux http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png Android is a variant of Linux system with ARM x86 Androids exist, though...
  • 47. Main Idea: Android is a Linux http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png Android is a variant of Linux system with ARM x86 Androids exist, though... Go supports ARM & Linux Officially with static-linking
  • 48. Main Idea: Android is a Linux http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png Android is a variant of Linux system with ARM x86 Androids exist, though... Go supports ARM & Linux Officially with static-linking Remember the philosophy of Unix
  • 50. Example Code https://github.com/sjp38/goOnAndroid https://github.com/sjp38/goOnAndroidFA Were demonstrated by live-coding from GDG Korea DevFair 2014 (http://devfair2014. gdg.kr/) and GDG Golang Seoul Meetup 2015 (https: //developers.google. com/events/5381849181323264/)
  • 51. Golang Process on Android: Plan 1. Cross compile Go program as ARM / Linux
  • 52. Golang Process on Android: Plan 1. Cross compile Go program as ARM / Linux 2. Include the binary in assets/ of Android app
  • 53. Golang Process on Android: Plan 1. Cross compile Go program as ARM / Linux 2. Include the binary in assets/ of Android app 3. Copy the binary in private space of the app
  • 54. Golang Process on Android: Plan 1. Cross compile Go program as ARM / Linux 2. Include the binary in assets/ of Android app 3. Copy the binary in private space of the app 4. Give execute permission to the binary /data/data/com.example.goRunner/files # ls -al -rwxrwxrwx u0_a55 u0_a55 4512840 2014-11-28 17:45 gobin
  • 55. Golang Process on Android: Plan 1. Cross compile Go program as ARM / Linux 2. Include the binary in assets/ of Android app 3. Copy the binary in private space of the app 4. Give execute permission to the binary 5. Execute it /data/data/com.example.goRunner/files # ls -al -rwxrwxrwx u0_a55 u0_a55 4512840 2014-11-28 17:45 gobin
  • 56. Go bin Loading Load golang program from assets to private dir private void copyGoBinary() { String dstFile = getBaseContext().getFilesDir().getAbsolutePath() + "/verChecker.bin"; try { InputStream is = getAssets().open("go.bin"); FileOutputStream fos = getBaseContext().openFileOutput( "verChecker.bin", MODE_PRIVATE); byte[] buf = new byte[8192]; int offset; while ((offset = is.read(buf)) > 0) { fos.write(buf, 0, offset); } Runtime.getRuntime().exec("chmod 0777 " + dstFile); } catch (IOException e) { } }
  • 57. Execute Go process Spawn new process for the program and communicates using stdio ProcessBuilder pb = new ProcessBuilder(); pb.command(goBinPath()); pb.redirectErrorStream(false); goProcess = pb.start(); new CopyToAndroidLogThread("stderr", goProcess.getErrorStream()) .start();
  • 58. Inter Process Communication Pros: Just normal unix way
  • 59. Inter Process Communication Pros: Just normal unix way Golang team is using this for Camlistore (https://github.com/camlistore/camlistore)
  • 60. Inter Process Communication Pros: Just normal unix way Golang team using this for Camlistore (https://github.com/camlistore/camlistore) Cons: Hacky, a little
  • 61. Summary You can use Golang for Android though it’s not stable yet Just for fun
  • 62. This work by SeongJae Park is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http: //creativecommons.org/licenses/by-sa/3.0/.