无法让 gomobile 绑定与 java 一起使用

Cannot get gomobile binding to work with java

转到版本: 1.7.5

GOPATH = D:/GoWork

React Native 版本 0.41

下面的代码是D:\GoWork\src\rngo\rngo\rngo.go

处的绑定go包

很简单,只返回一个字符串

package rngo

// RNcall is used to bind with RN
func RNcall()  string {
    return "From Go platform"
}

运行 以下命令来自 > D:\GoWork\src\rngo

gomobile bind -target android -o rngo.aar -v  .

下面的详细输出似乎没问题

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\classes.go

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\classes.h

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\classes.c

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gen\src\Java\interfaces.go rngo/rngo

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\fakegopath\pkg\android_arm\rngo\rngo.a write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\go_rngomain.go

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\go_main.go

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\androidlib\main.go

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\android\src\main\java\rngo\Rngo.java

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\java_rngo.c

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\rngo.h

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\android\src\main\java\go\Universe.java

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\android\src\main\java\go\error.java

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\java_universe.c

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\universe.h

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq_android.go

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq_android.c

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq.h

write C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq.go

Java /C/Users/Minty/AppData/Local/Temp/gomobile-work-855641675/gomobile_bind command-line-arguments rngo/rngo Java

/C/Users/Minty/AppData/Local/Temp/gomobile-work-855641675/gomobile_bind command-line-arguments rngo/rngo Java

/C/Users/Minty/AppData/Local/Temp/gomobile-work-855641675/gomobile_bind command-line-arguments rngo/rngo Java

/C/Users/Minty/AppData/Local/Temp/gomobile-work-855641675/gomobile_bind

/# /C/Users/Minty/AppData/Local/Temp/gomobile-work-855641675/gomobile_bind

D:\Android\sdk\ndk-bundle\toolchains\x86_64-4.9\prebuilt\windows-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin\ld: warning: skipping incompatible D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/liblog.so while searching for log

D:\Android\sdk\ndk-bundle\toolchains\x86_64-4.9\prebuilt\windows-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin\ld: warning: skipping incompatible D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/libdl.so while searching for dl

D:\Android\sdk\ndk-bundle\toolchains\x86_64-4.9\prebuilt\windows-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin\ld: warning: skipping incompatible D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/libc.so while searching for c

D:\Android\sdk\ndk-bundle\toolchains\x86_64-4.9\prebuilt\windows-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin\ld: warning: skipping incompatible D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/libdl.so while searching for dl

command-line-arguments

aar: AndroidManifest.xml

aar: proguard.txt

aar: classes.jar

jar: META-INF/MANIFEST.MF

jar: go/LoadJNI.class

jar: go/Seq$GoObject.class

jar: go/Seq$Proxy.class

jar: go/Seq$Ref.class

jar: go/Seq$RefMap.class

jar: go/Seq$RefTracker.class

jar: go/Seq.class jar: go/Universe$proxyerror.class jar: go/Universe.class

jar: go/error.class

jar: rngo/Rngo.class

aar: jni/armeabi-v7a/libgojni.so

aar: jni/arm64-v8a/libgojni.so

aar: jni/x86/libgojni.so

aar: jni/x86_64/libgojni.so

aar: R.txt

aar: res/

已成功创建 rngo.aar 因为没有错误消息,我可以在 D:[=102 看到该文件=]\rngo.aar

然后我手动将 rngo.aar 文件从 android studio

导入 React Native 项目
  1. File > New > New Module > Import .aar/.jar Package > #give the path 至 rngo.aar#
  2. 文件 > 项目结构 > 应用程序 > 依赖项 > 模块依赖 > rngo.aar

在IDE里面,在MainActivity.java里面我可以成功的做'import go.rngo.*;',但是我做不到'go.rngo.Rngo.RNcall()''go.rngo.Rngo;'上班

构建这个 android 应用程序抛出错误 'cannot find symbol'

D:\RN\gomobile\android\app\src\main\java\com\gomobile\RngoModule.java:10: error: cannot find symbol

import go.rngo;
^

symbol: class rngo
location: package go
1 error
:app:compileDebugJavaWithJavac FAILED

结论

我做错了一件非常可怕的事情,我无法让这个简单的东西工作。我在 google 上浪费了一整天,但无济于事。因此我需要帮助让它工作。我所需要的只是一个简单的 go 代码,它连接到 react native hasselfree。

感谢您阅读所有这些。非常感谢

感谢eliasnaur。最后,我得到了这个工作。从 go 1.7.* 开始,您无权访问 go 包。而是像这样直接访问您的包裹

之前:

import go.rngo.Rngo;

之后:(自 1.7.* 起)

import rngo.Rngo;