我在Go1.12.9 windows/ and 64中测试了GoMobile工具,并尝试将其附带的示例项目构建到Android中。
在将构建指向包目录并运行build命令时,控制台提供了一个无法找到包错误。如何识别Go包裹?
[注意-我试着安装和使用GoMobile工具,但它们也没有被识别,我只能通过VSCode下载它们作为Git包]。
PS D:\Script\Golang\bin> go version
go 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\basic
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 18-08-2019 11:27 4618 main.go
-a---- 18-08-2019 11:27 225 main_x.go
PS D:\Script\Golang\src\golang.org\x\mobile\example\basic> cd D:\Script\Golang\bin
PS 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)
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)
发布于 2019-08-28 16:14:39
Go获取与环境/系统variables.It中提供的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 或
由于戈朗使用GOPATH或GOROOT作为参考,包路径应该是
GOPATH\golang.org\x\mobile\example\basic
Golang将自动在环境变量中使用参考GOPATH,并在其后面附加路径。
因此,在上述情况下,所提供的包裹路径是-
PS D:\Script\Golang\bin> .\gomobile.exe build golang.org\x\mobile\example\basic
https://stackoverflow.com/questions/57691111
复制相似问题