Post on 17-Jul-2015
(Live) Build and run Golang Web server on
Android.aviSeongJae 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 socketReceive HTTP request from the socket
Web Server Client
url: /blahblah,method: GET
Web server
Processes request via HTTP protocol
Listen a socketReceive HTTP request from the socketProcess the request
Web Server Client
url: /blahblah,method: GET
Web server
Processes request via HTTP protocol
Listen a socketReceive HTTP request from the socketProcess the requestSend 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/804aa370f5adbf3d4377ee1b1e862cbc49d81c1c
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.pnghttp://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.pnghttp://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.pnghttp://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 ARMx86 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 ARMx86 Android exist, though...
Go supports ARM & Linux Officiallywith 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 ARMx86 Android exist, though...
Go supports ARM & Linux Officiallywith 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 / Linux2. Include the binary in assets/ of Android app
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app3. Copy the binary in private space of the app
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app3. Copy the binary in private space of the app4. 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 / Linux2. Include the binary in assets/ of Android app3. Copy the binary in private space of the app4. Give execute permission to the binary5. 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/devfair2014.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 LinuxGOOS=android has same problem, too :’(
(Live) Golang on Android: Solution
It has no /etc/hostsGet IP manually
Certifications path is differentUse 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/devfair2014.gdg.kr
Summary
Golang program can run on Android
Summary
Golang program can run on AndroidOfficially as .so or .apk file
Summary
Golang program can run on AndroidOfficially as .so or .apk fileOr, as elf binary with unofficial, little hack
Summary
Golang program can run on AndroidOfficially as .so or .apk fileOr, as elf binary with unofficial, little hack
Some features don’t work on Android, yetStill need some hacks
Final Source Code
go web server: https://github.com/sjp38/linuxOutYet/releases/tag/devfair2014.gdg.kr
go program runner(Android app): https://github.com/sjp38/goOnAndroidFA/releases/tag/devfair2014.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/.