Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: gomobile binding failed due to lack of some header file in Android NDK #39549

Open
ChronosXYZ opened this issue Jun 12, 2020 · 14 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ChronosXYZ
Copy link

ChronosXYZ commented Jun 12, 2020

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

$ go version
go version go1.14.4 linux/amd64

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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/chronosx/.cache/go-build"
GOENV="/home/chronosx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/chronosx/Документы/code/golang/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/5830"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/5830/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
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-build278490309=/tmp/go-build -gno-record-gcc-switches"

Android NDK version: 21.3.6528147

Gomobile version: gomobile version +4c31acb Sun Mar 29 12:56:38 2020 +0000 (android); androidSDK=

(I'm tried to use Go from Ubuntu repos, not only from Snap)

What did you do?

I'm trying to build some library which written in Go for Android (build AAR file).

gomobile: go build -tags mobile -ldflags -X github.com/yggdrasil-network/yggdrasil-go/src/version.buildName=yggdrasil -X github.com/yggdrasil-network/yggdrasil-go/src/version.buildVersion=0.3.14 -s -w  -buildmode=c-shared -o=/tmp/gomobile-work-131080533/android/src/main/jniLibs/armeabi-v7a/libgojni.so ./gobind failed: exit status 2
# runtime/cgo
gcc_android.c:6:10: fatal error: 'android/log.h' file not found

The file android/log.h exists in Android NDK.

What did you expect to see?

Library will compile successfully (it was compiled fine before).

What did you see instead?

I got the error:

gcc_android.c:6:10: fatal error: 'android/log.h' file not found
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jun 12, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jun 12, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 12, 2020
@toothrot
Copy link
Contributor

/cc @hyangah

@mirza-s
Copy link

mirza-s commented Jul 6, 2020

@ChronosX88

Are you building under $GOPATH? Building with go modules outside of $GOPATH might be the issue here.

@ChronosXYZ
Copy link
Author

@ChronosX88

Are you building under $GOPATH? Building with go modules outside of $GOPATH might be the issue here.

@mirza-s

I'm building the AAR file under $GOPATH, but error still exists.

@ChronosXYZ
Copy link
Author

Any updates?

@hajimehoshi
Copy link
Member

Have you set ANDROID_NDK_HOME environment variable?

@ChronosXYZ
Copy link
Author

ChronosXYZ commented Oct 26, 2020

Have you set ANDROID_NDK_HOME environment variable?

@hajimehoshi Yes, I've set all necessary environment variables.

ANDROID_NDK_HOME file listing:
изображение

@hajimehoshi
Copy link
Member

I've never tried to develop Android application on Linux so I don't have a good insight. Does regular Android application development work in your environment?

@ChronosXYZ
Copy link
Author

ChronosXYZ commented Oct 26, 2020

I've never tried to develop Android application on Linux so I don't have a good insight. Does regular Android application development work in your environment?

Yep, regular Android app is building correctly.

@ChronosXYZ
Copy link
Author

ChronosXYZ commented Oct 26, 2020

By the way, I know the location of log.h file (it is under $NDK/sysroot/usr/include/android dir). How to specify include dir for

#include <android/log.h>
? May be I should add some env vars, or smth like this?

@ChronosXYZ
Copy link
Author

The similar error appears in #14398.

@hajimehoshi
Copy link
Member

I don't think we really need it but how about setting C_INCLUDE_PATH?

@subins2000
Copy link

I was able to fix this by setting the CC variable : export CC=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android21-clang for x86

@jakubgs
Copy link

jakubgs commented Jun 9, 2022

I'm also seeing this issue using the most recent gomobile commit(golang/mobile@8578da9):

gomobile: gobind -lang=go,java -outdir=/build/gomobile-work github.com/status-im/go-waku/mobile failed: exit status 1
2022/06/09 16:15:42 err: exit status 2: stderr: go: downloading github.com/multiformats/go-multiaddr v0.5.0
go: downloading github.com/status-im/go-ethereum v1.10.4-status.2
go: downloading github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d
go: downloading github.com/libp2p/go-libp2p-core v0.16.1
go: downloading go.uber.org/zap v1.21.0
go: downloading github.com/libp2p/go-libp2p v0.20.0
go: downloading github.com/libp2p/go-libp2p-pubsub v0.6.1
go: downloading github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432
go: downloading go.opencensus.io v0.23.0
go: downloading github.com/libp2p/go-msgio v0.2.0
go: downloading github.com/golang/protobuf v1.5.2
go: downloading github.com/btcsuite/btcd/btcec/v2 v2.1.3
go: downloading golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
go: downloading github.com/status-im/go-discover v0.0.0-20220406135310-85a2ce36f63e
go: downloading github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
go: downloading github.com/golang-migrate/migrate/v4 v4.15.2
# runtime/cgo
gcc_android.c:6:10: fatal error: android/log.h: No such file or directory
    6 | #include <android/log.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.

I'm using NDK version 22.1.7171670 to build an AAR which works just fine for another application.

@jakubgs
Copy link

jakubgs commented Jun 9, 2022

What's interesting is when I strace the build, I can see there are two attempts by two separate GCC processes:

 > grep 'gcc_android.*fatal' /nix/store/aqf11zrgdzh0i4zr8gvdzk5b6hpiwrix-go-waku-devel/strace.log
535   write(2, "gcc_android.c:6:10: fatal error:"..., 140) = 140
347   <... read resumed>"gcc_android.c:6:10: fatal error:"..., 512) = 140
763   write(2, "gcc_android.c:6:10: fatal error:"..., 140) = 140
574   <... read resumed>"gcc_android.c:6:10: fatal error:"..., 512) = 140
 > grep 'gcc_android.*fatal' /nix/store/p1zh5y4bx9fg0hd47lwkr4k7ja01ind0-status-go-0.101.0-09ba88c-android/strace.log             
296   write(2, "gcc_android.c:6:10: fatal error:"..., 140) = 140
97    <... read resumed>"gcc_android.c:6:10: fatal error:"..., 512) = 164
525   write(2, "gcc_android.c:6:10: fatal error:"..., 140) = 140
328   <... read resumed>"gcc_android.c:6:10: fatal error:"..., 512) = 140

Except in the case of the latter, it continues and eventually builds it using android/log.h from Android SDK:

1663  openat(AT_FDCWD, "/nix/store/w4cxzkg3hx1li8yb3y79bp3npg2bffph-androidsdk/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/android/log.h", O_RDONLY|O_CLOEXEC <unfinished ...>
4185  openat(AT_FDCWD, "/nix/store/w4cxzkg3hx1li8yb3y79bp3npg2bffph-androidsdk/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/android/log.h", O_RDONLY|O_CLOEXEC <unfinished ...>
5623  openat(AT_FDCWD, "/nix/store/w4cxzkg3hx1li8yb3y79bp3npg2bffph-androidsdk/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/android/log.h", O_RDONLY|O_CLOEXEC <unfinished ...>

But I can't tell what's the difference. Both have ANDROID_HOME set and provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants