<p>I'm developing an Android app and plan on using Go for the backend. I'd like to use Android Studio for the Go development as well (Intellj J Go plugin), but I'm having trouble figuring out how Go works in Android Studio. For instance, where do the Go files fit in the project structure? Do I drop them into the src directory of the app module? Also, how do Go files fit in with Gradle? Any help would be greatly appreciated. </p>
<hr/>**评论:**<br/><br/>sdobz: <pre><p>This is fairly independent of android studio but I tend to put all of my go source in a subdirectory of my project and symlink it all into my go root. I use android studio (in my case pycharm) to work on the source and then use standard go tools to build and run it. If you have sufficient understanding of gradle to write custom code then do so, otherwise I would just do it by hand.</p></pre>the_web_dev: <pre><p>For me it's:</p>
<pre><code>/my-awesome-project
/bin
/pkg
/src
/third-party-lib-one
/third-party-lib-two
.gitignore
main.go
main_test.go
utils.go
utils_test.go
</code></pre>
<p>Don't forget to add the .idea and .iml files/dirs to your gitignore.. I always forget that.</p>
<p>I use standard go tools like build and get to work my project. Note sometimes Intellj go-plugin won't pick up the third party lib you just "go-getted", it's a simple fix just hover the red sguiggly line and select the go get -t option. I also use an independant terminal to run the tools, just because it seems faster.</p></pre>daveddev: <pre><p>It would probably be helpful to add <code>.idea</code> and <code>.iml</code> to ~/.gitignore_global (or wherever it is on your system). Then each project's .gitignore will not need to be muddled with your dev environment's needs.</p></pre>xlab_is: <pre><p>You may find useful my android-go examples here:
<a href="https://github.com/xlab/android-go/tree/master/example-egl" rel="nofollow">https://github.com/xlab/android-go/tree/master/example-egl</a></p>
<p>So you can pre-compile your Go package and include in Android.mk like this:</p>
<pre><code>LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := example
LOCAL_SRC_FILES := lib/libexample.so
LOCAL_LDLIBS := -llog -landroid
include $(PREBUILT_SHARED_LIBRARY)
</code></pre>
<p>Check out the Makefiles on how to build shared libraries using your Android SDK.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传