我正在 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
- 1 回答
- 0 關注
- 151 瀏覽
添加回答
舉報
0/150
提交
取消