(Live) Build and run
Golang Web server on
Android.avi
SeongJae Park <sj38.park@gmail.com>
Nice To Meet You
SeongJae Park
sj38.park@gmail.com
golang newbie programmer
Disclaimer
The main part of session is live-coding. This
slide has only little information.
Inspired by camlistore and outyet
Maybe useless, *just for fun*
Goal Of This Session
Build and run Golang web server on Android
Live Coding
golang: Programming Language
for simple, reliable, and efficient software.
http://blog.golang.org/5years/gophers5th.jpg
Web server
Processes request via HTTP protocol
Web Server Client
Web server
Processes request via HTTP protocol
Listen a socket
Receive HTTP request from the socket
Web Server Client
url: /blahblah,
method: GET
Web server
Processes request via HTTP protocol
Listen a socket
Receive HTTP request from the socket
Process the request
Web Server Client
url: /blahblah,
method: GET
Web server
Processes request via HTTP protocol
Listen a socket
Receive HTTP request from the socket
Process the request
Send HTTP response to client using the socket
Web Server Client
url: /blahblah,
method: GET
Status: OK,
Body: <p>welcome</p>
(Live) Simple Golang Webserver
…...
(Live) Simple Golang Webserver
…... complete
net/http rules
The code: https://github.
com/sjp38/linuxOutYet/tree/804aa370f5adbf3d
4377ee1b1e862cbc49d81c1c
Golang and Android
● Golang Supports Android officially from v1.4
○ The support focus on Application; just let .so or .apk
https://blog.golang.org/gopher/gopher.png
http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
Golang and Android
● Golang Supports Android officially from v1.4
○ The support focus on Application; just let .so or .apk
○ Requires complex build process and client code
https://blog.golang.org/gopher/gopher.png
http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
Golang and Android
● Golang Supports Android officially from v1.4
○ The support focus on Application; just let .so or .apk
○ Requires complex build process and client code
○ Couldn’t be more simple, easier?
https://blog.golang.org/gopher/gopher.png
http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
Golang on Android: Background
Android is a variant of Linux system with ARM
x86 Android exist, though...
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
Golang on Android: Background
Android is a variant of Linux system with ARM
x86 Android exist, though...
Go supports ARM & Linux Officially
with static-linking
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
Golang on Android: Background
Android is a variant of Linux system with ARM
x86 Android exist, though...
Go supports ARM & Linux Officially
with static-linking
So, why not?
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux
2. Include the binary in assets/ of Android app
Golang 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 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 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
(Live) Golang on Android
……
(Live) Golang on Android: Problem
…… Not successful
go binary runner code:
https://github.
com/sjp38/goOnAndroidFA/releases/tag/devfair
2014.gdg.kr
(Live) Golang on Android: Problem
…… Not successful
It has no /etc/hosts
CA Certs path is different with pure Linux
/system/etc/security/cacerts
(Live) Golang on Android: Problem
…… Not successful
It has no /etc/hosts
CA Certs path is different with pure Linux
/system/etc/security/cacerts
Android is a variant of, not pure Linux
GOOS=android has same problem, too :’(
(Live) Golang on Android: Solution
It has no /etc/hosts
Get IP manually
Certifications path is different
Use those certifications
(Live) Golang on Android: Again
……
(Live) Golang on Android
…… Complete
It’s hacky, but works
The code: https://github.
com/sjp38/linuxOutYet/releases/tag/devfair201
4.gdg.kr
Summary
Golang program can run on Android
Summary
Golang program can run on Android
Officially as .so or .apk file
Summary
Golang program can run on Android
Officially as .so or .apk file
Or, as elf binary with unofficial, little hack
Summary
Golang program can run on Android
Officially as .so or .apk file
Or, as elf binary with unofficial, little hack
Some features don’t work on Android, yet
Still need some hacks
Final Source Code
go web server: https://github.
com/sjp38/linuxOutYet/releases/tag/devfair201
4.gdg.kr
go program runner(Android app): https://github.
com/sjp38/goOnAndroidFA/releases/tag/devfair
2014.gdg.kr
This slide has been used for
GDG Korea DevFair 2014
GDG Korea Golang Seoul Meetup
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/.

(Live) build and run golang web server on android.avi

  • 1.
    (Live) Build andrun Golang Web server on Android.avi SeongJae Park <[email protected]>
  • 2.
    Nice To MeetYou SeongJae Park [email protected] golang newbie programmer
  • 3.
    Disclaimer The main partof session is live-coding. This slide has only little information. Inspired by camlistore and outyet Maybe useless, *just for fun*
  • 4.
    Goal Of ThisSession Build and run Golang web server on Android Live Coding
  • 5.
    golang: Programming Language forsimple, reliable, and efficient software. http://blog.golang.org/5years/gophers5th.jpg
  • 6.
    Web server Processes requestvia HTTP protocol Web Server Client
  • 7.
    Web server Processes requestvia HTTP protocol Listen a socket Receive HTTP request from the socket Web Server Client url: /blahblah, method: GET
  • 8.
    Web server Processes requestvia HTTP protocol Listen a socket Receive HTTP request from the socket Process the request Web Server Client url: /blahblah, method: GET
  • 9.
    Web server Processes requestvia HTTP protocol Listen a socket Receive HTTP request from the socket Process the request Send HTTP response to client using the socket Web Server Client url: /blahblah, method: GET Status: OK, Body: <p>welcome</p>
  • 10.
    (Live) Simple GolangWebserver …...
  • 11.
    (Live) Simple GolangWebserver …... complete net/http rules The code: https://github. com/sjp38/linuxOutYet/tree/804aa370f5adbf3d 4377ee1b1e862cbc49d81c1c
  • 12.
    Golang and Android ●Golang Supports Android officially from v1.4 ○ The support focus on Application; just let .so or .apk https://blog.golang.org/gopher/gopher.png http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
  • 13.
    Golang and Android ●Golang Supports Android officially from v1.4 ○ The support focus on Application; just let .so or .apk ○ Requires complex build process and client code https://blog.golang.org/gopher/gopher.png http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
  • 14.
    Golang and Android ●Golang Supports Android officially from v1.4 ○ The support focus on Application; just let .so or .apk ○ Requires complex build process and client code ○ Couldn’t be more simple, easier? https://blog.golang.org/gopher/gopher.png http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
  • 15.
    Golang on Android:Background Android is a variant of Linux system with ARM x86 Android exist, though... http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
  • 16.
    Golang on Android:Background Android is a variant of Linux system with ARM x86 Android exist, though... Go supports ARM & Linux Officially with static-linking http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
  • 17.
    Golang on Android:Background Android is a variant of Linux system with ARM x86 Android exist, though... Go supports ARM & Linux Officially with static-linking So, why not? http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
  • 18.
    Golang on Android:Plan 1. Cross compile Go program as ARM / Linux
  • 19.
    Golang on Android:Plan 1. Cross compile Go program as ARM / Linux 2. Include the binary in assets/ of Android app
  • 20.
    Golang 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
  • 21.
    Golang 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
  • 22.
    Golang 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
  • 23.
    (Live) Golang onAndroid ……
  • 24.
    (Live) Golang onAndroid: Problem …… Not successful go binary runner code: https://github. com/sjp38/goOnAndroidFA/releases/tag/devfair 2014.gdg.kr
  • 25.
    (Live) Golang onAndroid: Problem …… Not successful It has no /etc/hosts CA Certs path is different with pure Linux /system/etc/security/cacerts
  • 26.
    (Live) Golang onAndroid: Problem …… Not successful It has no /etc/hosts CA Certs path is different with pure Linux /system/etc/security/cacerts Android is a variant of, not pure Linux GOOS=android has same problem, too :’(
  • 27.
    (Live) Golang onAndroid: Solution It has no /etc/hosts Get IP manually Certifications path is different Use those certifications
  • 28.
    (Live) Golang onAndroid: Again ……
  • 29.
    (Live) Golang onAndroid …… Complete It’s hacky, but works The code: https://github. com/sjp38/linuxOutYet/releases/tag/devfair201 4.gdg.kr
  • 30.
  • 31.
    Summary Golang program canrun on Android Officially as .so or .apk file
  • 32.
    Summary Golang program canrun on Android Officially as .so or .apk file Or, as elf binary with unofficial, little hack
  • 33.
    Summary Golang program canrun on Android Officially as .so or .apk file Or, as elf binary with unofficial, little hack Some features don’t work on Android, yet Still need some hacks
  • 34.
    Final Source Code goweb server: https://github. com/sjp38/linuxOutYet/releases/tag/devfair201 4.gdg.kr go program runner(Android app): https://github. com/sjp38/goOnAndroidFA/releases/tag/devfair 2014.gdg.kr
  • 35.
    This slide hasbeen used for GDG Korea DevFair 2014 GDG Korea Golang Seoul Meetup
  • 36.
    This work bySeongJae 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/.