接触go之后,编译了一个用go写的项目,准备编译成aar,在Android 工程中使用。 这里记录下,编译时候遇到的问题,方便后续排查遇到的一样问题。
使用的编译命令:
当前路径: $GOPATH/src/
$ gomobile bind -target=android/arm64 -o out/diagnotic.aar diagnotic/
gomobile: go build -buildmode=c-shared -o=/var/folders/_g/m69td9r963bbq1rb4pjt2v340000gn/T/gomobile-work-664583801/android/src/main/jniLibs/arm64-v8a/libgojni.so ./gobind failed: exit status 1
/Users/*****/go/src/diagnotic/traceroute.go:12:2: cannot find package "golang.org/x/net/icmp" in any of:
/usr/local/go/src/golang.org/x/net/icmp (from $GOROOT)
/var/folders/_g/m69td9r963bbq1rb4pjt2v340000gn/T/gomobile-work-664583801/src/golang.org/x/net/icmp (from $GOPATH)
/Users/*****/go/src/golang.org/x/net/icmp
/Users/*****/go/src/diagnotic/traceroute.go:13:2: cannot find package "golang.org/x/net/ipv4" in any of:
/usr/local/go/src/golang.org/x/net/ipv4 (from $GOROOT)
/var/folders/_g/m69td9r963bbq1rb4pjt2v340000gn/T/gomobile-work-664583801/src/golang.org/x/net/ipv4 (from $GOPATH)
/Users/*****/go/src/golang.org/x/net/ipv4
/Users/*****/go/src/diagnotic/grpc.go:11:2: cannot find package "google.golang.org/grpc" in any of:
/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
/var/folders/_g/m69td9r963bbq1rb4pjt2v340000gn/T/gomobile-work-664583801/src/google.golang.org/grpc (from $GOPATH)
/Users/*****/go/src/google.golang.org/grpc
/Users/*****/go/src/diagnotic/grpc.go:12:2: cannot find package "google.golang.org/grpc/credentials" in any of:
/usr/local/go/src/google.golang.org/grpc/credentials (from $GOROOT)
/var/folders/_g/m69td9r963bbq1rb4pjt2v340000gn/T/gomobile-work-664583801/src/google.golang.org/grpc/credentials (from $GOPATH)
/Users/*****/go/src/google.golang.org/grpc/credentials
解决方案:
1、 github 中,寻找到对应的开源库, 下载到
$GOPATH/src/
目录下。
tips: 下载到本地的路径可能不对,需要修改成,错误提示中的路径