<p>gomobile has this <a href="https://godoc.org/golang.org/x/mobile/cmd/gobind#hdr-Reverse_bindings">reverse bindings</a> thing for a while. Has anyone played with that?</p>
<p>I've managed to build the <a href="https://github.com/golang/mobile/tree/master/example/reverse">reverse</a> example with gradle successfully (just go into the <em>android</em> directory and run <code>./gradlew assembleDebug</code>), but how is that when I add some <code>java.lang</code> imports to the reverse.go:</p>
<pre><code>import (
"Java/android/databinding/DataBindingUtil"
"Java/android/os"
"Java/android/support/v7/app"
gopkg "Java/reverse"
rlayout "Java/reverse/R/layout"
"Java/reverse/databinding"
"Java/reverse/databinding/ActivityMainBinding"
"Java/java/lang/Object"
"Java/java/lang"
)
</code></pre>
<p>then use it somewhere:</p>
<pre><code>type MainActivity struct {
app.AppCompatActivity
binding databinding.ActivityMainBinding
f lang.Object
}
</code></pre>
<p>and run <code>./gradlew assembleDebug</code> then <code>gobind</code> will fail on that it cannot find <code>java.lang</code> packages?</p>
<pre><code>:gomobileDebug
/home/micro/Workspace/bin/gomobile: loadExportData failed go install -pkgdir=/home/micro/Workspace/pkg/gomobile/pkg_android_arm -gcflags=-shared -ldflags=-shared
golang.org/x/mobile/example/reverse/reverse failed: exit status 1
../reverse/reverse.go:12:2: cannot find package "Java/java/lang" in any of:
/usr/lib/go/src/Java/java/lang (from $GOROOT)
/tmp/gomobile-work-498996765/gen/src/Java/java/lang (from $GOPATH)
/home/micro/Workspace/src/Java/java/lang
../reverse/reverse.go:13:2: cannot find package "Java/java/lang/Object" in any of:
/usr/lib/go/src/Java/java/lang/Object (from $GOROOT)
/tmp/gomobile-work-498996765/gen/src/Java/java/lang/Object (from $GOPATH)
/home/micro/Workspace/src/Java/java/lang/Object
:gomobileDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gomobileDebug'.
> Process 'command '/home/micro/Workspace/bin/gomobile'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
</code></pre>
<p>I've asked already on <a href="https://github.com/golang/go/issues/17945#issuecomment-285597585">github</a> and <a href="http://stackoverflow.com/questions/42967805/gomobile-reverse-bindings-classpath">stackoverflow</a> but no one answered. So I hope you guys can help :)</p>
<hr/>**评论:**<br/><br/>caseynashvegas: <pre><p>I've had some errors doing reverse bindings on iOS but never for Android, the following example compiles fine for me. </p>
<pre><code>package reverseTest
import (
"Java/java/lang"
"Java/java/lang/Object"
"fmt"
)
func TestReverseBinding() {
o := NewObject()
fmt.Println(o)
}
func NewObject() lang.Object {
return Object.New()
}
</code></pre></pre>caseynashvegas: <pre><p>I'd also highly recommend using import aliases for anything you do with reverse bindings, it makes the world much cleaner and prevents the tooling from barking (like the go extension in VS Code)</p>
<pre><code>import (
lang "Java/java/lang"
Object "Java/java/lang/Object"
"fmt"
)
</code></pre></pre>microo8: <pre><p>This example compiles, but when I start adding android classes it cannot find it. I'm trying to make an <em>WebView</em> app, so I need to import <code>android.webkit.WebView</code>. I've also tried to change the <code>buildToolsVersion</code> and java version. But it fails the same way.</p></pre>adgjzcb: <pre><p>go's related repository is <strong><a href="http://github.oldjpg.com/repository/7313744" rel="nofollow">go</a></strong> </p>
<blockquote>
<p>golang</p>
</blockquote></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传