Giter VIP home page Giter VIP logo

goandroid's Introduction

goandroid

Patches to the Go tools and runtime to enable Android apps to interface directly with a shared library written in Go. Goandroid also includes a simple demo written in Go, showing off OpenGL ES 2 and touch input.

Running Go code from Android apps is currently not possible, because the Go tools can only output executables while Android requires any foreign code in shared library (.so) format. This repository contains patches for the Go tools and runtime to enable shared library output, including workarounds to Android specific limitations. It also includes a simple example app written in Go to demonstrate OpenGL ES 2 graphics and touch input.

This guide assumes you're running linux and have an android device connected through USB.

Set up

  1. Make sure mercurial is installed

  2. Download and install the NDK. These instructions assumes the NDK is installed in $NDK.

  3. Create a standalone NDK toolchain (as described in $NDK/docs/STANDALONE-TOOLCHAIN.html):

    $NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=ndk-toolchain

    You might need to add --system=linux-x86_64 or --system=darwin-x86_64 depending on your system.

    Set $NDK_TOOLCHAIN to point at the ndk-toolchain directory

  4. Clone the golang repository:

    hg clone https://code.google.com/p/go

  5. Copy the patches directory to the go/.hg directory:

    cp -a patches go/.hg

  6. Enable the mq extension by adding the following lines to go/.hg/hgrc:

    [extensions]  
    mq =  
    
    [ui]  
    username = me<[email protected]>
    
  7. In the go/src directory apply the patches and build go:

    cd go/src  
    hg qpush -a  
    CGO_ENABLED=0 GOARCH=arm ./make.bash  
    CC="$NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc" GOARCH=arm GOARM=7 CGO_ENABLED=1 ../bin/go install -tags android -a -v std  
    cd ../..
    

Building and installing the example app

If everything is set up correctly, you should be able to run build.sh in the goandroid root to build and copy libandroid.so to android/libs. Then, running ant -f android/build.xml clean debug install will build and install the final apk to the connected device. Running the app should display a simple color animated triangle that you can move around the screen with your finger.

Go patches

All patches except android-tls and android-build-hacks correspond to the patches for linux/arm external linking and shared library support discussed on the golang-nuts mailing list.

The android-tls patch is a workaround for the missing support for the R_ARM_TLS_IE32 relocation in the Android linker.

The android-build-hacks patch contains various changes to account for the difference between a vanilla linux/arm system and Android.

goandroid's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.