GoMobile Build : Cannot find package

Starzar :

I was testing GoMobile tools in Go[1.12.9 windows/amd64] ,and tried to build the example projects that come with it into an Android Apk.
On pointing the build to the package directory and running the build command, the console gave a cannot find package error. How can the Go package be recognised?
[NOTE- I tried installing and using GoMobile tools,but they were also not recognised,I could only download them as a Git package via VSCode ]

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) 
Starzar :

Go takes path references with respect to the GOPATH or GOROOT path's provided in environment/system variables.It looks into the "src" directory in the GOPATH/GOROOT for the package .This means providing absolute package path will not work.

- Example(the above case )

GOPATH = D:\Script\Golang
GOROOT = C:\go
Absolute Package path = D:\Script\Golang\src\golang.org\x\mobile\example\basic

In this case, providing absolute package path will be read as

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

As golang uses GOPATH or GOROOT as reference , the package path should be

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

Golang automatically will use the reference GOPATH in the environment variables and append to it the path which comes after it.
So in the above case,the package path provided would be -

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related