工作需要,需要用到frp,源码地址:github.com/fatedier/fr… 为了适应业务需要改源码。故需要将一个go工程重编译成可供android使用的so或aar。
拿到一个不熟悉语言开发的工程,快速学习步骤如下:
1.开发环境的搭建
2.大概过一遍开发语言的语法
3.编译运行。去搜索该语言编译相关的文章。像Android工程,编译比较简单,直接运行即可。而go语言可编译的选项就非常多,可以是so,aar,apk,bin等等可执行文件。
4.调试。
前3步下来,基本流程就跑通了,后续修改源码后也能快速产出响应的编译后文件。
go源码可以编程成的文件格式有:
?TODO
可以编译成不同的文件格式意味这可以在不同平台运行,实现跨平台。
默认必备已经有JAVA SDK, ANDROID SDK, ANDROID NDK且都已经配置好环境变量。
1.下载安装go sdk
2.下载安装gomobile
Gomobile is a tool for building and running mobile apps written in Go.
To install:
$ go get golang.org/x/mobile/cmd/gomobile
$ gomobile init
At least Go 1.10 is required. For detailed instructions, see golang.org/wiki/Mobile.
Usage:
gomobile command [arguments]
Commands:
bind build a library for Android and iOS
build compile android APK and iOS app
clean remove object files and cached gomobile files
init build OpenAL for Android
install compile android APK and install on device
version print version
Use 'gomobile help [command]' for more information about that command.
配置gomobile:www.jianshu.com/p/6d2457e52…
1.安装gobind工具
go get golang.org/x/mobile/cmd/gobind
如果安装失败的话需要手动编译源码:
1).clone gomobile 项目到gopath/src/golang.org/x/路径下。
git clone https://gitee.com/yznzhankun/mobile.git
2).clone golang.org/x/mod 项目到gopath/src/golang.org/x/下。
git clone https://gitee.com/yznzhankun/mod.git
3).clone golang.org/x/xerrors 项目到gopath/src/golang.org/x/下。
https://gitee.com/yznzhankun/xerrors.git
4).clone golang.org/x/tools 项目到gopath/src/golang.org/x/下
https://gitee.com/yznzhankun/tools.git
5).继续编译安装gobind
go get golang.org/x/mobile/cmd/gobind
2.编译安装gomobile
go get golang.org/x/mobile/cmd/gomobile
3.配置Android NDK
1).下载NDK
2).解压NDK,并将NDK解压文件后的Ndk根路径设置给名为ANDROID_NDK_HOME的环境变量。
6.初始化gomobile
gomobile init
3.下载安装VSCode
4.编译成aar
gomobile bind -target=android github.com/fatedier/frp/cmd/frpc
#编译(不报错的情况)[root@localhost ~]# lsfrpclib.aar frpclib-sources.jar main.bak main.go