英文:
Cannot get gomobile binding to work with java
问题
以下是翻译好的内容:
Go版本:1.7.5
GOPATH = D:/GoWork
React Native版本:0.41
下面的代码是位于D:\GoWork\src\rngo\rngo\rngo.go的Go绑定包,非常简单,只返回一个字符串:
package rngo
// RNcall用于与RN绑定
func RNcall() string {
return "From Go platform"
}
从D:\GoWork\src\rngo运行以下命令:
gomobile bind -target android -o rngo.aar -v .
下面是详细输出,看起来没问题:
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\classes.go
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\classes.h
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\classes.c
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gen\src\Java\interfaces.go
rngo/rngo
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\fakegopath\pkg\android_arm\rngo\rngo.a
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\go_rngomain.go
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\go_main.go
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\androidlib\main.go
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\android\src\main\java\rngo\Rngo.java
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\java_rngo.c
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\rngo.h
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\android\src\main\java\go\Universe.java
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\android\src\main\java\go\error.java
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\java_universe.c
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\universe.h
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq_android.go
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq_android.c
写入 C:\Users\Minty\AppData\Local\Temp\gomobile-work-855641675\gomobile_bind\seq.h
写入 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: 警告: 跳过不兼容的 D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/liblog.so,正在搜索 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: 警告: 跳过不兼容的 D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/libdl.so,正在搜索 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: 警告: 跳过不兼容的 D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/libc.so,正在搜索 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: 警告: 跳过不兼容的 D:\Android\sdk\ndk-bundle\platforms\android-21\arch-x86_64/usr/lib/libdl.so,正在搜索 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:\GoWork\src\rngo\rngo.aar看到该文件。
然后,我手动将rngo.aar文件从Android Studio导入到React Native项目中:
- 文件 > 新建 > 新建模块 > 导入.aar/.jar包 > #给出rngo.aar的路径#
- 文件 > 项目结构 > app > 依赖项 > <点击> 模块依赖项 > rngo.aar
在IDE中,我可以成功地执行**'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: 错误: 找不到符号
import go.rngo;
^
symbol: class rngo
location: package go
1 error
:app:compileDebugJavaWithJavac FAILED
结论
我做错了什么,无法使这个简单的东西工作。我在Google上浪费了一整天的时间,但没有结果。因此,我需要帮助使其工作。我只需要一个简单的Go代码,可以与React Native无缝连接。
感谢您阅读所有内容。我非常感激。
英文:
Go version: 1.7.5
GOPATH = D:/GoWork
React Native version 0.41
Code below is the binding go package at D:\GoWork\src\rngo\rngo\rngo.go
Very simple, just returning a string
package rngo
// RNcall is used to bind with RN
func RNcall() string {
return "From Go platform"
}
Running the below command from > D:\GoWork\src\rngo
gomobile bind -target android -o rngo.aar -v .
Verbose Output below seems to be fine
> 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/
Successfully created rngo.aar since there is no error message and I can see that file at D:\GoWork\src\rngo\rngo.aar
I then manually import rngo.aar file into React Native project from android studio
- File > New > New Module > Import .aar/.jar Package > #give the path
to rngo.aar# - File > Project Structure > app > Dependencies >
<Cilcking> Module dependency > rngo.aar
Inside IDE, in MainActivity.java I can successfully do 'import go.rngo.*;', but I cannot get 'go.rngo.Rngo.RNcall()' or 'go.rngo.Rngo;' to work
Building this android app throws error '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
Conclusion
I am doing something horribly wrong, that I cannot get this simple thing to work. I wasted whole day on google but with no avail. Hence I need help getting this to work. All I need is a simple go code with that connects to react native hasselfree.
Thanks for reading all this. I appreciate it.
答案1
得分: 1
感谢 eliasnaur。最终,我搞定了。从 go 1.7.* 开始,你无法访问 go 包。而是直接像这样访问你的包
之前:
import go.rngo.Rngo;
之后:(自 go 1.7.* 起)
import rngo.Rngo;
英文:
Thanks to eliasnaur. Finally, I got this working. As of go 1.7.* you dont have access to go package. Instead access your package directly like this
Before:
import go.rngo.Rngo;
After:(Since 1.7.*)
import rngo.Rngo;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论