What's your experience with Go on mobile (bind only)?

polaris · · 419 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am writing a cross-platform app targeting both desktop and mobile (Android, iOS). I settled on either writing my business logic in C++ or Go, the UI is written separately for each platform.</p> <p>Are there any caveats to take into account when writing Go for mobile, if all I am using is the standard library and selected libraries from golang.org/x?</p> <p>E.g. I know that I can only target ARM platforms for Android, that&#39;s fine. But are there any subtle differences in using potentially platform-specific code, for example /x/crypto, file IO and networking on mobile? </p> <p>I guess what I am asking is: how much can I expect the Go standard library and extensions to be as rock-solid on mobile as on &#34;regular&#34; platforms.</p> <p>Thanks for your thought!</p> <p>Edit: I&#39;ve already seen the &#34;Go on Mobile&#34; slide deck from Hana Kim from 2015 [1], which states that Go Mobile is experimental. But is this still the case, and if so, which parts are prone to break?</p> <p>[1] <a href="https://talks.golang.org/2015/gophercon-go-on-mobile.slide#3">https://talks.golang.org/2015/gophercon-go-on-mobile.slide#3</a></p> <hr/>**评论:**<br/><br/>FZambia: <pre><p>Wrote about my experience with gomobile recently <a href="https://medium.com/@d47a3539410c/e72dc2736f01">https://medium.com/@d47a3539410c/e72dc2736f01</a></p></pre>caseynashvegas: <pre><p>I&#39;ve been successfully using gomobile bind to generate sdk applications for several months. It&#39;s a great way to share logic across ios and android and once you get it set up, it just works. </p> <p>There are some limitations of the data types that can be used in your exported interface, and those are documented on the wiki <a href="https://godoc.org/golang.org/x/mobile/cmd/gobind" rel="nofollow">https://godoc.org/golang.org/x/mobile/cmd/gobind</a></p> <p>Other than that, anything that is pure go seems to work including networking, file io, and I&#39;ve imported libraries such as bolt and used those. I haven&#39;t specifically used /x/crypto but no reason it shouldn&#39;t work. </p> <p>I&#39;d recommend watching the more current video from Elias Naur at <a href="http://www.thedotpost.com/2016/10/elias-naur-make-mobile-programming-fun-again" rel="nofollow">http://www.thedotpost.com/2016/10/elias-naur-make-mobile-programming-fun-again</a> to get a glimpse into reverse bindings, which I&#39;m avoiding for now, but they are working. </p></pre>Bbox55: <pre><p>Are you able to use the core concepts from Go? like Channel, interface and etc. There&#39;s also the ability to run Swift on Android, and Swift doesn&#39;t look that bad at all.</p></pre>caseynashvegas: <pre><p>Running swift on Android seems like more of a challenge right now compared to Go. At least it was the last time I researched it. All Go features are available to you when you use gomobile bind to generate an SDK, including channels, interfaces and go routines. </p> <p>On thing that is of particular value is that you can define an interface in Go, and implement it in your Obj-C/Swift or Java code to pass in dependencies to your Go code.</p> <p>An example of this would be if your go code wanted to raise a notification to the application, you could do this in Go:</p> <pre><code>package mySDK import ( &#34;time&#34; ) type Notifier interface { ShowNotification(title, message, string) } //now in a Go SDK method func DoSomethingInAGoroutine(notifier Notifier) { go func() { time.Sleep(time.Second * 5); notifier.ShowNotification(&#34;Done&#34;, &#34;Long running process completed&#34;) }() } </code></pre> <p>Then in your Obj C the interface &#34;Notifier&#34; would be generated as a protocol for you to implement, which you then pass to your go code</p> <p>MySDKDoSomethingInAGoroutine(self)</p></pre>still_unregistered: <pre><p>I gave a talk about gomobile at the FOSDEM this year, you could see it here <a href="https://www.youtube.com/watch?v=OaSkOjew1D4&amp;" rel="nofollow">https://www.youtube.com/watch?v=OaSkOjew1D4&amp;</a> the first bit wasn&#39;t recorded.</p> <p>I didn&#39;t have an iOS device, I could only talk about android development, I found it &#34;rock solid&#34;, didn&#39;t have a problem with my go code besides what android API allows you, for example, USB communication was possible, but you need to ask permission in Android first, and pass the file descriptor to go. Writing/reading files on the internal memory works out of the box, but for the external memory (SD, or what it&#39;s mounted when you connect it to the computer) wasn&#39;t that easy (again, you need to open the file in java and pass the FD to go),... internet works out of the box too.</p></pre>siwu: <pre><p>Very good, we have an app out that has at least 60% of its code written in Go on iOS and Android:</p> <ul> <li><p><a href="https://itunes.apple.com/us/app/zenly-locate-your-friends-in-realtime/id838848566?mt=8" rel="nofollow">https://itunes.apple.com/us/app/zenly-locate-your-friends-in-realtime/id838848566?mt=8</a></p></li> <li><p><a href="https://play.google.com/store/apps/details?id=app.zenly.locator&amp;hl=en" rel="nofollow">https://play.google.com/store/apps/details?id=app.zenly.locator&amp;hl=en</a></p></li> </ul></pre>112-Cn: <pre><p>You work at Zenly ? Nice ! I love it ! </p></pre>f2f: <pre><p>i&#39;ve been using gomobile for a pure Go android app for close to a year now. it has worked without failure although it&#39;s not deployed in production, only i use it daily myself.</p></pre>proyb2: <pre><p>No idea, I have tried to play around SCADE.io which use Swift and compile native app to iOS and Android. What more, if design UI need to be consistent for both platforms, it use SVG. Seem easy to get started.</p> <p>Could you get Go running any Android SDK?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

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