golang gomobile 环境搭建
- 安装Go语言SDK
https://www.golangtc.com/download - 配置系统变量这建立
GOROOT
和GOPATH
两个目录,分别对应sdk所在目录与项目文件根目录 - 输入
go version
验证是否成功 - 安装gomobile
1. cmd敲起命令(需要CMDFQ)
go get golang.org/x/mobile/cmd/gomobile
gomobile init
2. git clone https://github.com/golang/mobile
,下载成功后改文件名为mobile, copy到$GOPATH/src/golang.org/x/
如果没有文件路径,自行创建
2.1 go build golang.org/x/mobile/cmd/gomobile
,此时会在GOPATH/bin
下面生成gomobile
;
2.2 执行gomobile init
, 会在GOPATH/bin
下面生成gobind;
gomobile init
执行不会报错,如果有问题,执行bind时会报错;
执行init后,执行gomobile version
,查看是否成功:
将gomobile,gobind拷贝, sudo cp gomobile gobind /usr/local/go/bin;
因为执行gomobile bind时,回去系统path里找gobind;
下载:AndroidNDK
选择符合的操作系统及位数的NDK包:https://developer.android.google.cn/ndk/downloads/index.html
解压,放到一个你记得住的目录
3) 尝试编译第一个Android apk安装包cmd命令:gomobile build -target=android golang.org/x/mobile/example/basic
如果提示 “No android NDK path is set“,需要以下代码指定NDK路径
gomobile init -ndk "你的AndroidNDK路径"
然后再编译,编译成功后会把编译后的APK(%GOPATH%\src
)安装包放到CMD当前指向的目录中
ft_authoradmin ft_create_time2019-03-30 17:32
ft_update_time2019-03-30 17:37
ft_update_time2019-03-30 17:37