36
(Live) Build and run Golang Web server on Android.avi SeongJae Park <[email protected]>

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

Embed Size (px)

Citation preview

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

(Live) Build and run Golang Web server on

Android.aviSeongJae Park <[email protected]>

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

Nice To Meet You

SeongJae Park

[email protected]

golang newbie programmer

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

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*

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

Goal Of This Session

Build and run Golang web server on Android

Live Coding

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

golang: Programming Language

for simple, reliable, and efficient software.

http://blog.golang.org/5years/gophers5th.jpg

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

Web server

Processes request via HTTP protocol

Web Server Client

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

Web server

Processes request via HTTP protocol

Listen a socketReceive HTTP request from the socket

Web Server Client

url: /blahblah,method: GET

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

Web server

Processes request via HTTP protocol

Listen a socketReceive HTTP request from the socketProcess the request

Web Server Client

url: /blahblah,method: GET

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

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>

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

(Live) Simple Golang Webserver

…...

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

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

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

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

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

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

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

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

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

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

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

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

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

Golang on Android: Plan

1. Cross compile Go program as ARM / Linux

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

Golang on Android: Plan

1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app

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

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

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

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

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

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

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

(Live) Golang on Android

……

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

(Live) Golang on Android: Problem

…… Not successful

It has no /etc/hosts

CA Certs path is different with pure Linux/system/etc/security/cacerts

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

(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 :’(

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

(Live) Golang on Android: Solution

It has no /etc/hostsGet IP manually

Certifications path is differentUse those certifications

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

(Live) Golang on Android: Again

……

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

Summary

Golang program can run on Android

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

Summary

Golang program can run on AndroidOfficially as .so or .apk file

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

Summary

Golang program can run on AndroidOfficially as .so or .apk fileOr, as elf binary with unofficial, little hack

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

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

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

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/.