Coder Social home page Coder Social logo

rakesh-mohanta / android-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xlab/android-go

0.0 3.0 0.0 117 KB

The android-go project provides a platform for writing native Android apps in Go programming language.

Home Page: https://developer.android.com/ndk/index.html

License: MIT License

Makefile 0.99% Go 97.43% C 1.31% Assembly 0.27%

android-go's Introduction

android-go Go Report Card Lines of Code

The android-go project aims to provide a platform (namely an SDK) for writing native Android apps in Go programming language. All things here were designed to be less coupled as possible, thus maintaining a great level of flexibility while keeping things simple and easy to use. The approach and tools are different from gomobile, please distinguish them apart.

Project structure

android GoDoc

Package android provides Go bindings for the Android NDK API. They've been automatically generated by a tool not yet announced (sorry :)) using the official NDK headers from android-23 platform. Keep in mind that different NDK platforms may implement different sets of API available, thus some of features used by this binding may not be available in older versions of platform. But I tested with the android-21 toolchain and got no issues. Some files, like android/sensors.go for example, have been written by hand to expose some features that CGO does not handle well.

This package allows to write code that works directly with NDK API, bypassing all the CGO bookkeeping and boilerplate bloat in your code. But safety is strictly advised.

Example usages: app/queue.go, example, example-egl

app GoDoc

Package app implements a NativeActivity glue layer required to properly handle the startup process and the native activity events. Import this package into your Go application to make it Android-compatible. Some pieces required for a proper main.main trampoline have been borrowed from gomobile, the absolute minimum to get this stuff invokable as a native activity. Most of the code in this package provides wrappers around NativeActivity event callbacks.

Example usages: example, example-egl

egl GoDoc

Package egl provides Go bindings for EGL API. They've been automatically generated by a tool not yet announced (sorry :)) using the official NDK headers from android-23 platform. All functions have their reference to the offical Khronos documentation. Some files, like egl/errors.go for example, have been written by hand to expose some features that would make it more idiomatic in the Go world.

Example of usage in conjuction with the android package: example-egl.

gles GoDoc

Package gles provides Go bindings for the OpenGL ES v1 API. They've been automatically generated by a tool not yet announced (sorry :)) using the official NDK headers from android-23 platform. All functions have their reference to the offical documentation.

Example of usage in conjuction with the android package: example-egl.

gles2 GoDoc

Package gles2 provides Go bindings for the OpenGL ES v2 API. They've been automatically generated by a tool not yet announced (sorry :)) using the official NDK headers from android-23 platform. All functions have their reference to the offical documentation.

Examples

Refer the example links to get more info about them.

There are two beautiful examples. The first example is a template showing how to create and build an application using the absolute minimum of code and boilerplate. It also shows the primitives of an activity and how to handle activity events, there is no visual part, so be ready to read the lines in the ADB Shell. If this one works correctly on your device, my congratulations. If not, please open an issue.

And example-egl leverages all three packages together: android, egl and of course gles to create quite a rich app that animates its color based on the accelerometer values. It also reads input events such as key events and multitouch motion events (with pressure, if supported by the device), you can check these events in the ADB Shell. Check out the video of the expected behaviour:

Golang + EGL/GLES App on Android

On existing tools or why not just use Gomobile

TL;DR it's a three wheel bicycle.

GoMobile has different aims and motivation with a lot of implications. First of all, it has been grown as a bootstrap-script. That's it: a tool with a lot of hardcoded logic that helped to popularize Go on mobile platforms. Still provides a simple way to start building Android and iOS apps in no time, without diving deeply into any of the platform-specific complications. It provides a lot of wrappers and helpers that abstract all the platform-related boilerplate and logic away, making your apps look the same on any platform: Android, iOS, PC (Linux/OS X/Windows), the latter is for debug purposes. It also downloads a stripped prebuilt SDK/NDK for you.. oh wait!!1

So, for Android developent, gomobile defaults to r10 SDK with android-15 stripped-down NDK, there is a lot of code written to automate this process and there is no way to override this environment, even by rewriting a lot of gomobile bootstrapping code. It's a great mess. Too much time wasted trying to switch to the r12-beta1 SDK and the android-23 NDK platform. Instead of providing a good document how to build the Go-based apps and incorporate them into any of the existing development process, the Gomobile project introduces tons of hardcoded scripts in Go. Nuff said, even the article that shows the principle behind the main.main trampoline does it by reverse engineering an APK produced by Gomobile. Any self-documenting code? Hell no.

Contributing

Feel free to share bugs, I expect a lot of weird cases. Please also share this project in social networks so more people would know how to write Go apps for Android that are not limited. Follow me at @xlab_dev.

License

All the code except when stated otherwise is licensed under the MIT license.

android-go's People

Contributors

xlab avatar

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.