golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124k stars 17.67k forks source link

x/mobile: gobind failed: exit status 2 #33998

Open unifyproxy opened 5 years ago

unifyproxy commented 5 years ago

What version of Go are you using (go version)?

$ go version
go version go1.12.9 linux/amd64

What version of Gomobile are you using (gomobile version)?

$ gomobile version
gomobile version +c6da959 Fri Aug 30 20:13:51 2019 +0000 (android); androidSDK=/home/jason/Android/Sdk/platforms/android-29

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jason/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jason/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build025736357=/tmp/go-build -gno-record-gcc-switches"

What did you do?

gomobile bind -target android -o v2.aar github.com/v2ray/v2ray-core

What did you expect to see?

nothing (build success)

What did you see instead?

Error
gomobile: /usr/local/go/bin/go build -buildmode=c-shared -o=/tmp/gomobile-work-571427279/android/src/main/jniLibs/armeabi-v7a/libgojni.so gobind failed: exit status 2
# gobind
core_android.c:380:1: error: redefinition of 'Java_core_InboundHandlerConfig_getTag'
core_android.c:306:1: note: previous definition is here
core_android.c:554:1: error: redefinition of 'Java_core_OutboundHandlerConfig_getTag'
core_android.c:480:1: note: previous definition is here
core_android.c:573:1: error: redefinition of 'Java_core_OutboundHandlerConfig_getExpire'
core_android.c:468:1: note: previous definition is here
core_android.c:588:1: error: redefinition of 'Java_core_OutboundHandlerConfig_getComment'
core_android.c:460:1: note: previous definition is here
katiehockman commented 5 years ago

/cc @hyangah

WesleyBatista commented 2 years ago

I hit this issue while trying to build this project: ipfs-shipyard/gomobile-ipfs (from the packages folder)

go version 1.18.2 was being used and there was one go module in dependency chain requiring go 1.17:

# github.com/lucas-clemente/quic-go/internal/qtls
../pkg/mod/github.com/lucas-clemente/quic-go@v0.24.0/internal/qtls/go118.go:6:13: cannot use "quic-go doesn't build on Go 1.18 yet." (untyped string constant) as int value in variable declaration
[...]
github.com/ipfs/go-pinning-service-http-client
golang.org/x/mobile/bind/seq
golang.org/x/mobile/bind/java
/tmp/go-build1282703176/b001/exe/gomobile: go build -v -buildmode=c-shared -o=/tmp/gomobile-work-69347995/android/src/main/jniLibs/armeabi-v7a/libgojni.so ./gobind failed: exit status 2

exit status 1
make: *** [Makefile:112: /home/wesley/devel/gomobile-ipfs/packages/build/android/intermediates/core/core.aar] Error 1

I've installed go 1.17.11 and it fixed the issue for me.


go env output: ``` GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/wesley/.cache/go-build" GOENV="/home/wesley/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/wesley/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/wesley/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.2" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/wesley/devel/gomobile-ipfs/packages/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1673722584=/tmp/go-build -gno-record-gcc-switches" ```
ZekeLu commented 2 years ago

@WesleyBatista Your issue is not the same. github.com/lucas-clemente/quic-go does not support Go 1.18 until 0.25.0. See https://github.com/lucas-clemente/quic-go/releases/tag/v0.25.0

WesleyBatista commented 2 years ago

@ZekeLu thanks for your comment!

I understand my issue is not the same, but I believe the root cause lies in the fact that there was an unexpected outcome during the build (a package/module failed to build) that ultimately caused the exit status 2 we see at the end, which is pretty much the same as op.

In my case the problem was the go version, but exit code 2 could be anything that fails and causes a misuse of shell built-ins, as described here: https://tldp.org/LDP/abs/html/exitcodes.html

shahinfasihi commented 1 year ago

does anybody have any idea how to fix the problem that @unifyproxy mentioned?

i tried to generate .aar file but i get the same error go version => 1.20 ndk version => 21.3.6528147 (tried to use the latest but i get an error so i switch to the earlier one and then fix the problem with ndk version) but i get the same error when trying to bind go code (gomobile bind -v -androidapi 19 -ldflags='-s -w' ./) repo =>V2fly error =>

# gobind/gobind core_android.c:272:1: error: redefinition of 'Java_core_InboundHandlerConfig_getTag' core_android.c:235:1: note: previous definition is here core_android.c:377:1: error: redefinition of 'Java_core_OutboundHandlerConfig_getTag' core_android.c:340:1: note: previous definition is here core_android.c:396:1: error: redefinition of 'Java_core_OutboundHandlerConfig_getExpire' core_android.c:328:1: note: previous definition is here core_android.c:411:1: error: redefinition of 'Java_core_OutboundHandlerConfig_getComment' core_android.c:320:1: note: previous definition is here gomobile: go build -v -ldflags -s -w -buildmode=c-shared -o=/tmp/gomobile-work-2973778891/android/src/main/jniLibs/arm64-v8a/libgojni.so ./gobind failed: exit status 1