user285594
user285594

Reputation:

How to run my Go code in Android?

How can i run this Go code in my Android? (in Fedora 15 its working).

package main
import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

Upvotes: 11

Views: 5133

Answers (2)

nocrox
nocrox

Reputation: 65

With Go 1.0, the compilers changed from separate compiler executables for different target architectures to a single compiler executable. Thus, the process of compiling for ARM is slightly different from Go 1.0 on:

CGO_ENABLED=0
GOOS=linux
GOARCH=arm
go build main.go

The (environment) variables GOOS and GOARCH have to be set to match the android environment, which is a linux OS and an ARM hardware architecture. Then you can use go build as you would compile for any other platform (which will then act according to the set variables).

Upvotes: 3

Mostafa
Mostafa

Reputation: 28086

You have to compile it for ARM, and thankfully it is very easy with Go's compilers:

$ 5g main.go && 5l main.5

The executive binary (5.out) will be runnable on Android. Just copy it there and run with shell. More info here.

Upvotes: 11

Related Questions