-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: support vendored asset package on Android #26445
Comments
Update. Same problem even if I compile my go directly into the app (with the correct gradle settings) rather than build an aar with gomobile bind and then link the aar to the app |
/cc @eliasnaur |
Please provide a complete example that demonstrates this issue. I can't reproduce it, and there is even a test for reading assets in gomobile bind programs: |
Sample here. https://github.com/derekwbrown/testrepo/tree/master/android |
The asset succeeds in being read on an emulator (android 8.1.0) and my Google Pixel (android 8.1.0). What device are you using? Can you reproduce in an emulator? Is the log saying something relevant before the "no current JVM"? |
Device is Nexus 7 running android 5.1.1 logs prior to |
Unfortunately, even with an 5.1.1 emulator, I fail to reproduce the error. Are you using the latest checkout of gomobile (I'm on revision 371a4e8cb797fc2ab3793091822fda6179a73102) and have up to date binaries (go install golang.org/x/mobile/cmd/...)? Also, can you reproduce the error with Go 1.11 beta 2? |
Did as you asked, same problem. I recompiled go with
then reinstalled and rebuilt gomobile
Made sure I was also vendoring in the latest gomobile... contents of |
For what it's worth, my android NDK is |
OK... so that we're looking at the exact same thing... |
Thank you for the docker instructions; I can reproduce the error now. The problem is that there are two versions of the golang.org/x/mobile packages: one in GOPATH/src, and one in the vendor/ directory created by dep. The package generated by gomobile bind uses the one in GOPATH/src, and at runtime, Seq.java supplies the context to that package. On the other hand, your hello.go calls into the vendored golang.org/x/mobile/asset package that hasn't been initialized. If you (Edited to correct my mistake in thinking Seq.java called into the vendored version.) |
I'm not sure what the correct fix is, but I changed the issue title to match the problem: multiple versions of the the asset package, which in turn means multiple versions of the internal/mobileinit package, which has global variables for the JVM and application context. In Android Java API, you're expected to always pass in an android.context.Context, while the Go asset package expects access to assets without any context. |
so, to clarify, I shouldn't vendor in the |
That's right. I'm keeping the issue open for a future solution that safely allows vendoring mobile packages for bind programs. |
Great. Thank you for all of your help. |
See golang/go#26445 and golang/go#33254 Co-authored-by: songqifu <songqifu@linakesi.com> Co-authored-by: Changkun Ou <hi@changkun.de>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version devel +2acae87416 Mon Jul 9 23:04:30 2018 +0000 windows/amd64
go/mobile version is also latest from master
Does this issue reproduce with the latest release?
This is on latest master/built from source (to resolve other gomobile problem).
What operating system and processor architecture are you using (
go env
)?This may be the same as #25255
Note my build environment is windows; i have reproduced the problem using a linux
build environment; target environment is android
go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\db\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=d:\dev\go
set GOPROXY=
set GORACE=
set GOROOT=c:\devtools\go1.11.devel
set GOTMPDIR=
set GOTOOLDIR=c:\devtools\go1.11.devel\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\db\AppData\Local\Temp\go-build567116882=/tmp/go-build -gno-record-gcc-switches
set VGOMODROOT=
What did you do?
I have an android app that creates a service. The service is built linking to a library
created with
gomobile bind
What did you expect to see?
Everything works
What did you see instead?
When the service starts, it immediately crashes with
I/GoLog (18112): asset: no current JVM
I/Zygote ( 195): Process 18112 exited cleanly (1)
The first thing the service does is attempt to load an asset (which is present in the .apk)
The text was updated successfully, but these errors were encountered: