How were you intending to run the Go program? iirc you'll need access to a Context that can only be provided by the Dalvik VM, and that can only be instantiated via bytecode ran on the VM (so use Java). The first entry point this is provided is Application.onCreate when said class is declared in the AndroidManifest.
This isn't a limitation of Go and has always been the case for native code ran on Android unless something has changed recently in the last few major versions I'm unaware of. On Thu, Oct 12, 2017, 5:43 PM <audrius.butkevic...@gmail.com> wrote: > Your example has a MainActivity.java. > As I said, this is a Go application, and as it stands it has no Java, so > it doesn't have (and doesn't intend to have) a main activity. > Also, your initialization (Hello.initContentProvider) happens from Java > (not from Go), so my question is still unanswered of how do do all of this > purely from the Go side without reverse bindings. > > On Thursday, 12 October 2017 09:58:54 UTC+1, Elias Naur wrote: >> >> Hi, >> >> As I noted on the issue, you should avoid the reverse binding for now and >> use Go interfaces instead. The following change to the gomobile bind >> example demonstrates the technique: >> >> diff --git >> a/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java >> b/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java >> index 47248d9..fce9a7b 100644 >> --- >> a/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java >> +++ >> b/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java >> @@ -11,6 +11,8 @@ import android.os.Bundle; >> import android.widget.TextView; >> >> import hello.Hello; >> +import hello.ContentProvider; >> +import hello.Writer; >> >> public class MainActivity extends Activity { >> >> @@ -25,5 +27,16 @@ public class MainActivity extends Activity { >> // Call Go function. >> String greetings = Hello.greetings("Android and Gopher"); >> mTextView.setText(greetings); >> + >> + Hello.initContentProvider(new ContentProvider() { >> + @Override public Writer open(String name) throws >> Exception { >> + return new Writer() { >> + @Override public long >> write(byte[] data) throws Exception { >> + return 0; >> + } >> + }; >> + } >> + }); >> + Hello.useContentProvider(); >> } >> } >> diff --git a/example/bind/android/hello/build.gradle >> b/example/bind/android/hello/build.gradle >> index 92fb0bd..11345e4 100644 >> --- a/example/bind/android/hello/build.gradle >> +++ b/example/bind/android/hello/build.gradle >> @@ -4,7 +4,7 @@ >> */ >> >> plugins { >> - id "org.golang.mobile.bind" version "0.2.9" >> + id "org.golang.mobile.bind" version "0.2.7" >> } >> >> gobind { >> diff --git a/example/bind/hello/hello.go b/example/bind/hello/hello.go >> index 2d98ff9..96301da 100644 >> --- a/example/bind/hello/hello.go >> +++ b/example/bind/hello/hello.go >> @@ -10,3 +10,28 @@ import "fmt" >> func Greetings(name string) string { >> return fmt.Sprintf("Hello, %s!", name) >> } >> + >> +var contentProvider ContentProvider >> + >> +type ContentProvider interface { >> + Open(name string) (Writer, error) >> +} >> + >> +type Writer interface { >> + Write(b []byte) (int, error) >> +} >> + >> +func InitContentProvider(cp ContentProvider) { >> + contentProvider = cp >> +} >> + >> +func UseContentProvider() { >> + w, err := contentProvider.Open("test") >> + if err != nil { >> + // handle error >> + } >> + _, err = w.Write([]byte("data")) >> + if err != nil { >> + // handle error >> + } >> +} >> >> >> The gobind plugin downgrade is https://github.com/golang/go/issues/21594. >> >> - 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. > -- 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.