为了账号安全,请及时绑定邮箱和手机立即绑定

GoMobile 构建:找不到包

GoMobile 构建:找不到包

Go
叮当猫咪 2023-07-17 15:14:36
我正在 Go[1.12.9 windows/amd64] 中测试 GoMobile 工具,并尝试将其附带的示例项目构建到 Android Apk 中。将构建指向包目录并运行构建命令时,控制台给出了“找不到包”错误。Go包如何被识别?[注意- 我尝试安装和使用GoMobile 工具,但它们也无法识别,我只能通过 VSCode 将它们下载为 Git 包]PS D:\Script\Golang\bin> go versiongo version go1.12.9 windows/amd64  PS D:\Script\Golang\src\golang.org\x\mobile\example\basic> gci    Directory: D:\Script\Golang\src\golang.org\x\mobile\example\basicMode                LastWriteTime         Length Name----                -------------         ------ -----a----       18-08-2019     11:27           4618 main.go-a----       18-08-2019     11:27            225 main_x.goPS D:\Script\Golang\src\golang.org\x\mobile\example\basic> cd D:\Script\Golang\binPS D:\Script\Golang\bin> .\gomobile.exe build D:\Script\Golang\src\golang.org\x\mobile\example\basicD:\Script\Golang\bin\gomobile.exe: cannot find package "D:\\Script\\Golang\\src\\golang.org\\x\\mobile\\example\\basic" in any of:        c:\go\src\D:\Script\Golang\src\golang.org\x\mobile\example\basic (from $GOROOT)        D:\Script\Golang\src\D:\Script\Golang\src\golang.org\x\mobile\example\basic (from $GOPATH)S D:\Script\Golang\bin> .\gomobile.exe build "D:\Script\Golang\src\golang.org\x\mobile\example\basic"D:\Script\Golang\bin\gomobile.exe: cannot find package "D:\\Script\\Golang\\src\\golang.org\\x\\mobile\\example\\basic" in any of:        c:\go\src\D:\Script\Golang\src\golang.org\x\mobile\example\basic (from $GOROOT)        D:\Script\Golang\src\D:\Script\Golang\src\golang.org\x\mobile\example\basic (from $GOPATH) 
查看完整描述

1 回答

?
Qyouu

TA贡献1786条经验 获得超11个赞

Go 采用相对于环境/系统变量中提供的 GOPATH 或 GOROOT 路径的路径引用。它会在GOPATH/GOROOT 中的“src”目录中查找包。这意味着提供绝对包路径将不起作用。

- 示例(以上案例)

GOPATH = D:\Script\Golang
GOROOT = C:\go
绝对包路径 = D:\Script\Golang\src\golang.org\x\mobile\example\basic

在这种情况下,提供绝对包路径将被读取为

GOPATH\D:\Script\Golang\src\golang.org\x\mobile\example\basic
 GOROOT\D:\Script\Golang\src\golang.org\x\mobile\example\basic

由于golang使用GOPATH或GOROOT作为参考,所以包路径应该是

GOPATH\golang.org\x\mobile\example\basic

Golang 将自动使用环境变量中的引用 GOPATH 并将其后面的路径附加到它后面。
因此,在上述情况下,提供的包路径将是 -

PS D:\Script\Golang\bin> .\gomobile.exe 构建 golang.org\x\mobile\example\basic


查看完整回答
反对 回复 2023-07-17
  • 1 回答
  • 0 关注
  • 63 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信