Go on Android

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Original address:on android ' >go, on android Author: Orange InfinityThe efficiency of Go language has always made me want to use it for Android, a lot of things, purely from the perspective of the code, with go to write will be much easier. This article is just an example, there is no substantive meaning, just a few records at the time of development.
I do not want to say how to get the source of go or how to compile, those on the internet everywhere can be found, recommended direct reference to the official Go language website (http://golang.org/), there are many valuable things.
The same reference to the official website, we can compile the GO environment to support the arm, using the environment compiled programs, can also run on Android.
Then compile the go itself, so that it can compile the application under ARM, modify the. bashrc file on Android "title=" [Reprint]go, On Android "/>

At the end, add the following entry on Android "title=" [Reprint]go, On Android "/>

PATH depends on where your Go source is downloaded, not necessarily the same as me.
Then compile the source code, it's simple. On Android "title=" [Reprint]go, On Android "/>

Just wait a few minutes to compile and compile a bunch of files on the $GOROOT/bin. Android "title=" [Reprint]go, On Android "/>

This means success, if you have previously compiled Go, the directory contains 8g,8l and other files, it is possible to switch to arm compilation will fail. This time the entire Go source code can be deleted, and then re-download the compilation.
I have written a simple update module, which is implemented as follows
1) write the Go module, the implementation of the module is very simple, the start of the current version number, and then retrieve the latest version number from the server side, if the server side version is newer, then return to the new version of the download path, otherwise return an empty string (security, server address hidden part, hehe) on Android "/>
This side with the editor is VI, the background is set to translucent, so behind a desktop background, perhaps some people will feel so uncomfortable, but my habit is to put some information such as open in the back, so that the side coding can look at the data, do not have to switch windows repeatedly, or very convenient.
The picture is the complete source code, in order to display in a screen, do some of the line merger things (cough, screen small no way.) Do not learn this when you are actually writing code:)
2) Compile the Go code, according to the following several commands, note that the arm compiler is 5g, the linker is 5lon Android "title=" [Reprint]go, On Android "/>

After compiling, you will get a 5.out file, rename the file to update, note that it does not require a suffix name
3) Verification function, put the update file directly into Android to perform a trial on Android "title=" [Reprint]go, On Android "/>

This means that validation is successful
4) Use this file in apk
It is too lazy to write, direct reference to the foreigner's article, in fact, very simple main practice is: Put the update into the assets directory, and then in the program to save it to a private directory and give permissions, and then execute and get the return value. As for why this module is not made into JNI form, because the current Go does not support JNI, but I believe it will soon be, after all, this is Google's own things, how to say will gradually put the support for Android to improve.
For reference please click here to enter
All right, that's it, enjoy your coding:)
    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.