GO語言已經可以寫Android項目了,你知道嗎?

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

新的庫名叫go.mobile,包含了Go for Android的庫的工具

在go.mobile庫的readme中有介紹開發環境的搭建,不過僅限於早期版本,整合進IDE的構建系統還沒有呢。

  1. 首先需要Android SDK,和NDK。
  2. 然後需要添加一個環境變數:NDK_ROOT=$HOME/android/ndk-toolchain
  3. 配置NDK工具ndk/build/tools/make-standalone-toolchain.sh -platform=android-9 --install-dir=$NDK_ROOT
  4. 安裝Go cross-compiler
    1. hg clone https://code.google.com/p/go
    2. cd go/src
    3. CC_FOR_TARGET=$NDK_CC GOOS=android GOARCH=arm GOARM=7 ./make.bash
  5. 如果之前有安裝過GO,那預設情況下是for電腦平台的,所以這裡要構建ARM的。大概是這個意思。
  6. 將go/bin添加到path環境變數中
利用Go,可以開發兩種項目,一種是android JAVA代碼調用到go,另一種就是純Go寫的APP,第二種就是提供了open gl和完全的golang開發環境。


Apps are written in Java, developed using the standard Android
tools, that include a Go library for added functionality. There is an
example of such a library in go.mobile/example/libhello.


To build the shared library, use the make.bash script in the example's
directory. It requires an environment variable, ANDROID_APP, set to the
location of your Android studio project. E.g.


    ANDROID_APP=$HOME/android/studio/yourapp/app


With this variable, make.bash builds the .so file and symlinks in the
necessary java files to the project.




Go Android apps (games)
-------------


Go Android apps are built on top of the NDK's NativeActivity. These apps
are written entirely in Go. An example of such an app, with touch events
and OpenGL, is in go.mobile/example/basic.


To build and deploy the app to the device currently attached to adb,
use the all.bash script in the example's directory. It requires
ndk-build, ant, and adb on your PATH.


APIs are currently very limited, but under active development.


To submit changes to this repository, see http://golang.org/doc/contribute.html.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.