I am a go newbie. I am trying to install gomobile for evaluation on MacOS BigSur but can't get past the init step.
running go version returns go version go1.17.6 darwin/amd64
Following the directions, the gomobile install appears to work properly (after explicitly adding gomobile to my PATH), but running init or version fails.
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
go install: version is required when current directory is not in a module
Try 'go install golang.org/x/mobile/cmd/gobind@latest' to install the latest version
gomobile version unknown: cannot test gomobile binary: exit status 1, no required module provides package golang.org/x/mobile/cmd/gomobile: go.mod file not found in current directory or any parent directory; see 'go help modules'
I'm guessing this has something to do with environment variables but any suggestions and/or help would be appreciated.
I did manage to finally get gomobile set up, but the process was painful and the official "experimental" documentation was incomplete and not at all helpful. Here's the steps that worked for me on MacOS (BigSur):
Follow steps to install GO from website
Install gomobile
go install golang.org/x/mobile/cmd/gomobile@latest
Install Xcode command line tools. If installed but not found, you may need to run the following:
xcode-select -r
Install Android NDK. This can be done via Android Studio’s Tools->SDK Manager. Need to ensure that the installed version is supported by gomobile since the latest version of the NDK is NOT supported by gomobile.
Update shell to include the following exports:
export PATH=$PATH:/Users/mikem/go/bin
export ANDROID_HOME=/Users/mikem/Library/Android/sdk
export ANDROID_NDK_HOME=/Users/mikem/Library/Android/sdk/ndk/23.1.7779620
Create a working directory
mkdir myworkdir
Create a module directory
mkdir mymodule
cd mymodule
Create a .go file in that module directory and give it some content. Note that the package name should be different than the module name or the bind may complain that it can't find anything
package mymodulelib
import "fmt"
func SayHello() {
fmt.Println("Hello from mymodule")
}
From the work directory, initialize the module
go mod init mymodule
Install gobind - it will complain that you should be using the go install method instead of the go get (deprecated) but the go install does not work (at least for me)
go get golang.org/x/mobile/cmd/gobind
Go back into the module directory, initialize and then generate iOS and android code
cd mymodule
gomobile init
gomobile bind -target ios
gomobile bind -target android
After installation, please use the following command:
export PATH=$PATH:~/go/bin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With