I'm running into an issue with reverse bindings similar to this. My project structure is like:
mobile/ └── pkg └── example ├── android │ └── javatest.go └── testmobile.go *testmobile.go:* package example import ( "mobile/pkg/example/android" ) func SystemCurrentTimeMillis() int64 { return android.SystemCurrentTimeMillis() } *android.go:* package android import ( "Java/java/lang/Float" "Java/java/lang/System" ) func SystemCurrentTimeMillis() int64 { return System.CurrentTimeMillis() } func FloatMin() float32 { return Float.MIN_VALUE } When I run gomobile bind on the top-level example package, it fails: mobile/pkg/example/android/javatest.go:4:2: could not import Java/java/lang/Float (cannot find package "Java/java/lang/Float" in any of: If I run gomobile on the android directory, it works. Is it expected that the above imports should work, or does gomobile bind only work on one package? Thanks, -Kelly On Thursday, April 25, 2019 at 6:43:19 PM UTC-4, Mark Bauermeister wrote: > > Ok. I fixed it. > > For anybody interested, here's how I solved it. > > On the Go side, I extended my exported function by adding "ctx > content.Context" as a parameter (i e "func Hello(ctx content.Context). > On the Java side, I'm then passing the mobile context as follows (this is > a React Native app, so it's bound to different from regular Android apps): > > Context ctx = getReactApplicationContext(); > Mobile.hello(ctx); > > > I can then access the application context from the Go side. > > Now one thing that would be interesting still is whether/how I can reverse > bind "com.facebook.react.bridge.ReactContextBaseJavaModule" on the Go side > directly, > so I can call "getReactApplicationContext()" directly from the Go side > rather than pass the context in from Java. > > I know there's "-classpath" but how does it actually work for external > Java libraries? > > On Wednesday, 24 April 2019 15:27:31 UTC+2, Mark Bauermeister wrote: >> >> Yea. Turns out that was indeed the issue. I tried accessing a method that >> didn't actually exist. >> >> Unfortunately, your code doesn't work either. It leads to a segmentation >> violation/nil pointer error. >> I suspect one needs to somehow get the right context from the Java side. >> Question is how. >> >> I already tried an OnCreate override func, but that one is somehow never >> called. >> >> On Wednesday, 24 April 2019 15:08:02 UTC+2, ma...@eliasnaur.com wrote: >>> >>> >>> >>> On Wednesday, April 24, 2019 at 2:34:34 PM UTC+2, Mark Bauermeister >>> wrote: >>>> >>>> I'm currently experimenting with Gomobile Reverse Bindings (my hope is >>>> to eventually be able to call getFilesDir(), so I can save my SQLite3 DB >>>> on >>>> mobile) and it is, quite literally, driving me insane. >>>> I've followed the sparse information available, was able to >>>> successfully work with 'import "Java/java/lang/System" and call >>>> "System.currentTimeMillis()". >>>> >>>> Now I'm trying to import "Java/android/content" and it fails outright, >>>> stating that the package "Java/android/content" cannot be found. >>>> >>>> What is the correct import path for Android packages, or is there >>>> something else I need to do that I'm missing? >>>> >>> >>> Note that reverse binding packages will only be generated if you use a >>> type from it; importing is unfortunately not enough. >>> >>> Perhaps >>> >>> import "Java/android/content" >>> >>> var ctx content.Context >>> ctx.GetFilesDir() >>> >>> is enough to get further. >>> >>> The reverse bindings are very fickle, sorry. >>> >>> - elias >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.