Use the Go language to pack an AAR package for Android

Source: Internet
Author: User
Tags install go

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.