Using the Go language to develop Android programs

Source: Internet
Author: User
Tags install go
This is a creation in Article, where the information may have evolved or changed.

Environment configuration

    1. Install Go 1.5 or later, the specific installation steps are available on the official website Https://golang.org/doc/install
    2. Installing Gomobile Https://godoc.org/golang.org/x/mobile/cmd/gomobile
      Execute the following command, you may need to flip the wall during installation

      go get -v golang.org/x/mobile/cmd/gomobilegomobile init -v

The following issues may occur during the installation process

    1. Prompt unrecognized import path error, usually after turning over the wall can be resolved
    2. Prompt import path does not begin with hostname error, if set GOROOT then cancel this setting
    3. Prompt $GOPATH not set for errors, check for settings GOPATH and do not add when using commandssudo
    4. Prompting a directory for missing permissions, authorizing the current usersudo chown -R <当前用户名> <提示的目录名>

Writing code

    1. Create an Android project and write native code. Note: The targetsdkversion for Android Works cannot be 23.
    2. Create the corresponding app package name under Gopath and write the GO code.
    3. Create a new Gradle module under Android Engineering and modify the module's build.gradle file.

       plugins {ID "org.golang.mobile.bind" version "0.2.4"}gobind {//Go app package name pkg = "com. Bookislife/goandroid "//Gopath path, can be viewed by executing ' go env ' to view Gopath ="/users/sidney/gopath "//go binary file go ="/usr/loca L/cellar/go/1.5.3/bin/go "//gomobile binary file, default to ' Gopath/bin/gomobile ', if installed in other directories need to manually specify//Gomobile ="/users/sidne Y/gopath/bin/gomobile "}  
    4. ensures that the Settings.gradle for Android app root target references this module.
    5. compiles the go code, ./gradlew Gobind , and the AAR file containing the Native file is generated under the Go module created in step 3 when the compilation is complete.
    6. normally uses the Native code in Android Engineering, and subsequent operations are the same as for normal applications.
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.