use https://github.com/shangzebei…
package main
import (
"fmt"
"unsafe"
"gitee.com/aifuturewell/gojni/java"
)
func main() {}
func init() {java.OnMainLoad(func(reg java.Register) {reg.WithClass("com.nk.Hello").
BindNative("nice", "void(java.lang.String[])", nice).
Done()})
}
func nice(ss []string) {fmt.Println(ss)
}
在 java 中
package com.nk;
public class Hello {
static {System.loadLibrary("test");
}
public static void main(String[] args) {nice(new String[] {"come", "from", "gojni"});
}
public static native void nice(String[] sss);
}
golang build and run
go build -buildmode=c-shared -o libtest.so
LD_LIBRARY_PATH=. java com.nk.Hello