x/mobile: ndk-build finds wrong library path for dlopen #17807
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
Hi,
Based on the Android NDK samples (https://github.com/googlesamples/android-ndk/tree/master) and mainly the hello-libs, I'm trying to call a prebuilt library.
In fact, it is pretty simple for a C-based library (using the examples), but when my .so is built using Go, the ndk-build linker seems to go crazy and uses an intermediate path to reference the .so library which causes the app crash.
Go versions
go version go1.7.1 darwin/amd64
gomobile version +6ecf8ee Sun Oct 16 10:25:40 2016
Go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/dev/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b_/y2nd3vgn4m1929dg56thjdn40000gn/T/go-build047047925=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Steps
On the gomobile example directory, create an Android binding library :
cd $GOPATH/src/golang.org/x/mobile/example/bind/hello
gomobile bind -target android
extract the so library from the resulting aar.
create a simple .h header to reference the symbol (Java_go_hello_Hello_Greetings)
add the result to the sample project (the same thing as gperf)
without even referencing the function on the main cpp, build the project (gradle build) --> build successful
install the resulting apk
What did you expect to see?
a working app
What did you see instead?
java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/me/Desktop/vm-win/ndk-build-golang/hello-libs-2/app/src/main/cpp/../../../../distribution/libgo/lib/arm64-v8a/libgojni.so" not found
after decomposing the code and focusing only on the library build (basic ndk project) I still get the same thing :
java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/me/dev/android-ndk/hello-libs/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libgojni.so" not found
When I check the symbols on the intermediate library (libhello-libs.so) I see that the libgojni.so is referenced with a full path instead of just the filename (which is the case of a C-based library)
(both libraries are at the same level when I extract the apk)
Thanks,
additional info
A C-based library is working but not the Go-based one. Maybe the latter is missing something ?
I've uploaded a buildable project to https://github.com/ab-smith/ndk-build-golang
I can make it work by patching the libhello-libs.so and fixing the path binary, but this is not a solution.
The text was updated successfully, but these errors were encountered: