//go:generate javac -bootclasspath $ANDROID_HOME/platforms/android-29/android.jar AClass.java //go:generate jar cf AClass.jar AClass.class //go:generate rm AClass.class package main import ( "fmt" "log" "time" "gioui.org/app" ) func callJni() { time.Sleep(time.Second/5) jvm := app.JavaVM() ctx := app.AppContext() labchan <- fmt.Sprintf("JVM = %d", jvm) labchan <- fmt.Sprintf("Context = %d", ctx) SetJVM(jvm, ctx) RunInJVM(func(env *JNIEnv) { log.Print("finding class") cls := FindClass(env, "st/wow/git/jni/AClass") log.Print("getting methodID") mth := JniGetMethodID(env, cls, "Num", "()I") if mth == nil { labchan <- "nil method" return } log.Print("creating object") inst := CreateObject(env, cls) log.Print("calling method") val := JniCallIntMethod(env, inst, mth) log.Print("got result") labchan <- fmt.Sprintf("val = %d", val) }) }