One, Environment construction
1. Install Go
A. Download address: https://golang.org/dl/
B. The version downloaded here is Go1.5.2.windows-amd64.zip
C. Then unzip the Go folder inside the tarball to the D packing directory
D. Configuring environment variables Goroot and Gopath
E. Goroot value is D:/go
F. New Folder D:/gopath
G. Setting the environment variable Gopath value to D:/gopath
H. Increase in the PATH environment variable;%goroot%/bin;%gopath%/bin
2. Install Go Mobile
$go Get Golang.org/x/mobile/cmd/gomobile
→ If you cannot access golang.org, you can access https://github.com/golang/mobile, download the source program directly, and copy the Mobile folder to the $GOPATH/src/golang.org/x/
Perform $go build Golang.org/x/mobile/cmd/gomobile
$go Install Golang.org/x/mobile/cmd/gomobile
Gomobile.exe generation can be found under $GOPATH/bin after completion
3, affiliate Android NDK (recommended to use Android Tudio download)
$gomobile init-v The directory of your NDK
4, write Go program, I casually write a paragraph
Package Gotestfunc
ADD (x int, y int) int {
return x + y
}
In the go language, note that functions must be capitalized before they can be exported.
5. Compiling go
On the command line, CD to the directory where your. Go file is located, then execute the command
Gomobile bind-target=android
An. aar file is generated when you finish running
6. New Android Project
Open Android Studio, create a new project, select your project right-click New in the left Project panel, select module, choose Import Jar/aar, select the AAR file created in step 5th.
7. Import
Add the imported module to the created project dependencies in project structure.
8. Reference Documents
https://blog.csdn.net/HJLAllen1/article/details/51920170
https://blog.csdn.net/phlong999/article/details/49613931
https://blog.csdn.net/lanyu19950216/article/details/50456732