使用Go语言打包Android 的aar包

栏目: Go · 发布时间: 6年前

一,环境搭建

 1、安装Go

a. 下载地址为: https://golang.org/dl/

b. 这里下载到的版本为 go 1.5.2.windows-amd64.zip

c. 然后将压缩包里面的go文件夹解压到D盘根目录

d. 配置环境变量GOROOT和GOPATH

e. GOROOT值为D:/go

f. 新建文件夹D:/GOPATH

g. 设置环境变量GOPATH值为D:/GOPATH

h. 在PATH环境变量中增加 ;%GOROOT%/bin;%GOPATH%/bin

2、安装go mobile

$go get golang.org/x/mobile/cmd/gomobile

→如果无法访问golang.org,可以访问 https://github.com/golang/mobile ,直接下载源程序,并将mobile文件夹拷贝到在 $GOPATH/src/golang.org/x/ 下

执行    $go build golang.org/x/mobile/cmd/gomobile

$go install golang.org/x/mobile/cmd/gomobile

完成后可以在 $GOPATH/bin 下可以发现 gomobile.exe 生成

3、关联Android ndk (建议使用Android tudio下载) 

 $gomobile init  -v 你的ndk的目录

4、编写go程序,我随便写了段

package goTestfunc

Add(x int, y int) int {

return x + y

}

Go语言里要注意下,函数必须首字母大写的才能导出,否则无法导出

命令行里,先cd到你.go文件所在目录,然后执行命令

gomobile bind -target=android

运行完后会生成一个.aar文件

打开android studio,新建项目,建好后在左边项目面板中选中你的项目右键new,选择Module,选择导入jar/aar,选中第5步里创建的aar文件。

在Project Structure中将导入的Module添加到创建的项目Dependencies中。

8 参考文档

https://blog.csdn.net/HJLAllen1/article/details/51920170

https://blog.csdn.net/phlong999/article/details/49613931

https://blog.csdn.net/lanyu19950216/article/details/50456732


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Intersectional Internet

The Intersectional Internet

Safiya Umoja Noble、Brendesha M. Tynes / Peter Lang Publishing / 2016

From race, sex, class, and culture, the multidisciplinary field of Internet studies needs theoretical and methodological approaches that allow us to question the organization of social relations that ......一起来看看 《The Intersectional Internet》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具