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: bind/java/seq_test.go cannot find aar on latest android studio #10668

Closed
crawshaw opened this issue May 2, 2015 · 3 comments
Closed

Comments

@crawshaw
Copy link
Member

crawshaw commented May 2, 2015

When running go test, adb logcat reports:

F/go/Seq  (13579): cannot find go/Seq

It looks like go.Seq is in the testpkg.aar, but gradle is not making it part of the apk.

@timcooijmans
Copy link
Contributor

Same problem here.
The go.Seq class file is not included in the build: It is missing in the intermediate/classes directory, where I would expect it. Only the R.class file from the go java-package is present.
I tried to explicitly tell proguard not to trim the classes but that doesn't solve the problem.

@hyangah
Copy link
Contributor

hyangah commented May 5, 2015

@crawshaw : I could reproduce the problem myself. The class files are in the apk (so, Go.init was called) and could be found from the app package but not from bind/java package. It seems that when find_class is called from the Go thread, a wrong class loader was picked up. Verified with logging the exception details.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
"You can get into trouble if you create a thread yourself (perhaps by calling pthread_create and then attaching it with AttachCurrentThread). Now there are no stack frames from your application. If you call FindClass from this thread, the JavaVM will start in the "system" class loader instead of the one associated with your application, so attempts to find app-specific classes will fail."

I will try to cache the loader or class from JNI_OnLoad as recommended in the doc.

@timcooijmans Is the problem related to the bind/java/seq_test.go? In seq_test.go setup, go.Seq is in build/intermediates/exploded-aar/testpkg/classes.jar.

@timcooijmans
Copy link
Contributor

@hyangah I'm seeing exactly the same problem in other projects. However both in seq_test.go and in my project I was surprised to see that the go-related Java-class-files were not present during gradle-building in the intermediate/classes directory. I expected them there but maybe I am wrong on that.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
This allows the application class loader to be used when
the bind/java package or other part of JNI dynamically
loads java classes from a non-Java thread.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass

Fixes golang/go#10668.

Change-Id: I44df3a9362617fa6dd26ddf88247e4fdaee7c7e8
Reviewed-on: https://go-review.googlesource.com/9732
Reviewed-by: David Crawshaw <crawshaw@golang.org>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
This allows the application class loader to be used when
the bind/java package or other part of JNI dynamically
loads java classes from a non-Java thread.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass

Fixes golang/go#10668.

Change-Id: I44df3a9362617fa6dd26ddf88247e4fdaee7c7e8
Reviewed-on: https://go-review.googlesource.com/9732
Reviewed-by: David Crawshaw <crawshaw@golang.org>
@rsc rsc unassigned hyangah Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants