Anyone with a gomobile reverse bindings experience?

polaris · · 498 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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&#39;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 ( &#34;Java/android/databinding/DataBindingUtil&#34; &#34;Java/android/os&#34; &#34;Java/android/support/v7/app&#34; gopkg &#34;Java/reverse&#34; rlayout &#34;Java/reverse/R/layout&#34; &#34;Java/reverse/databinding&#34; &#34;Java/reverse/databinding/ActivityMainBinding&#34; &#34;Java/java/lang/Object&#34; &#34;Java/java/lang&#34; ) </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 &#34;Java/java/lang&#34; 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 &#34;Java/java/lang/Object&#34; 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 &#39;:gomobileDebug&#39;. &gt; Process &#39;command &#39;/home/micro/Workspace/bin/gomobile&#39;&#39; 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&#39;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&#39;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 ( &#34;Java/java/lang&#34; &#34;Java/java/lang/Object&#34; &#34;fmt&#34; ) func TestReverseBinding() { o := NewObject() fmt.Println(o) } func NewObject() lang.Object { return Object.New() } </code></pre></pre>caseynashvegas: <pre><p>I&#39;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 &#34;Java/java/lang&#34; Object &#34;Java/java/lang/Object&#34; &#34;fmt&#34; ) </code></pre></pre>microo8: <pre><p>This example compiles, but when I start adding android classes it cannot find it. I&#39;m trying to make an <em>WebView</em> app, so I need to import <code>android.webkit.WebView</code>. I&#39;ve also tried to change the <code>buildToolsVersion</code> and java version. But it fails the same way.</p></pre>adgjzcb: <pre><p>go&#39;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

498 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传