golang / go

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

x/mobile: Android gobindPlugin doesn't package *.so into the apk for the very first build #23766

Closed vickyramachandra closed 6 years ago

vickyramachandra commented 6 years ago

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

go1.8.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/user/goprojects" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y8/ylh63k1106ldg8t7q3jrl701s3tf0r/T/go-build239147691=/tmp/go-build -gno-record-gcc-switches -fno-common" CXX="clang++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2"

What did you do?

Gradle version - 4.5.1 Android plugin version - 3.0.1 I am using the android plugin gobindPlugin 0.2.10 to build my go source files and include them into the android app. I use the gradle wrapper to execute the gradle commands. When i execute one of the gradle build commands (eg ./gradlew build) for the very first time (i.e there is no prior gradle cache present -> .gradle/ folder isn't generated yet), i could see that the native files .so isn't packaged into my final apk. Hence when i run the app, finding the go methods fails, resulting in UnsatisfiedLinkError. However it is included in the successive builds (i.e when the gradle cache is once created). Also if i don't use the gobindPlugin and prebuild my go source files as .aar using the gomobile bind command and place them into the libs folder under the android app and include them as compile dependencies in my gradle script, the .so files are correctly packaged.

P.S - Make sure that app/build and app/src/main/jniLibs and .gradle/ directories aren't present inside the android project before any of the gradle commands are executed

What did you expect to see?

The native *.so packaged in my apk

What did you see instead?

Native files are missing in the apk

vickyramachandra commented 6 years ago

cc @hyangah

hyangah commented 6 years ago

Sorry that I don't have time to look into this issue for now. I am guessing the plugin needs additional checks or dependency specification. Contribution is really welcome. Once it's fixed, I will happily build and upload a new version.

vignesh-ramachandra commented 6 years ago

Hey hana, please look into it when you get time https://go-review.googlesource.com/c/mobile/+/94835 :)

gopherbot commented 6 years ago

Change https://golang.org/cl/94835 mentions this issue: mobile/misc/androidstudio: Fixing gobind build issues for Android builds

hyangah commented 6 years ago

0.2.11 is out.

vickyramachandra commented 6 years ago

Thanks a lot @hyangah 👍:)

hyangah commented 6 years ago

Thank you for actually fixing it @vickyramachandra