mandala

A Go framework for writing native Android applications

  • Owner: remogatto/mandala
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Mandala

GoDoc

Mandala is a framework for writing Android native applications in
Go using the
Goandroid toolchain. You can
develop, test and run your application on your desktop and then deploy
it to an Android device. It encourages the use of idiomatic Go for
writing Android applications: communication happens through channels and
not callbacks. The framework should not be considered a high-level
game engine but as a basic layer onto which game engines can be built
or existing ones can be used. In my opinion, this opens interesting
scenarios in the developing of native Android applications/games in
Go. Goandroid's
native_activity
example was the initial source of inspiration for this project.

Please consider that Mandala is in a very early stage of development:
API will change, test coverage is not so good for now. Last but not
least, Go doesn't officially support native Android
development. Regarding this point, I hope that the present work could
act as a sort of incentive in the direction of an official Android
support by the Go Team.

Have a nice Mandala!

Key features

  • Code/test/run on your desktop and deploy on the device.
  • Build/deploy/run your application using simple shell commands.
  • On-device black-box testing.
  • Communicate through channels, no callbacks.
  • Quick bootstrap using a predefined template.

Supported desktop platforms

  • Linux (xorg)
  • OSX (see the wiki page)

Techonologies involved

How does it work?

Mandala uses the Goandroid toolchain to compile Go
applications for Android. The graphics abstraction between desktop and
device is obtained using a bunch of technologies. In particular

  • EGL
  • OpenGL ES 2.0
  • GLFW 3

The EGL layer is necessary to use an OpenGL ES 2 context on a
desktop environment. The GLFW library is responsible of managing the rendering
context and the handling of events in a window.

The framework itself provides an event channel from which client code
listen for events happening during program execution. Examples of
events are the interaction with the screen, the creation of the native
rendering context, pausing/resuming/destroying of the application,
etc.

The framework abstracts the Android native events providing a way to
build, run and test the application on the desktop with the promise
that it will behave the same on the device once deployed. Oh well,
this is the long-term aim, at least!

A typical Mandala application has two loops: one continuously listens for
events, the other is responsible for rendering the scene. In order to
dealing with application resources (images, sounds, configuration
files, etc.), the framework provides a ResourceManager object. Client
code sends requests to it in order to obtain resources as slices of
bytes. In the desktop application this simply means opening the file
at the given path. In the Android application the framework will
unpack the apk archive on the fly getting the requested resources from
it. However, it is the framework's responsibility to deal with the right
native method for opening a file. From the client-code point of view the
request will be the same.

The bothersome steps needed to build, package and deploy the
application on the device are simplified using a set of predefined
gotask tasks.

Examples

Please visit
mandala-examples.

Prerequisites

  • Android NDK
  • Goandroid
  • EGL
  • OpenGL ES 2
  • GLFW3
  • gotask (to run the tests)
  • xdotool (to run the tests on xorg)

Android NDK

See here.

Goandroid

See here.

After installing Goandroid
you have to export a new environment variable GOANDROID. It
should point to the Go bin folder of the Goandroid
distribution. For example,

Also note that on a 32 bit host machine, it would be necessary to
generate the toolchain with:

See here for further info about the issue.

EGL/OpenGL ES 2

On a debian-like system:

Then you should install the Go bindings for EGL and OpenGL ES 2. This
is as simple as:

GLFW3

Install from source following the instructions
here. Please note that
you have to configure GLFW in order to use EGL and OpenGL ES 2. For
further information, see
here
and
here. Be
sure to build GLFW as a shared object!

After installing GLFW3, in order to install the Go binding, see
here.

gotask

xdotool

On a debian-like system:

This is needed for black-box testing only.

Install

Once you have satisfied all the prerequisites:

This will install all the remaining dependencies.

Quick start

To create a basic application install mandala-template:

Then, in a folder inside $GOPATH/src run the following
commands:

This will generate a simple Android application showing a red
screen. See
mandala-template for
furher info.

Testing

Setup a testing environment on Android was not straightforward. The
main issue is
related to the flag package. To avoid dependency from it I
had to hack PrettyTest in
order to remove the dependency from testing (which in turn
depends on flag). So basically, testing a native Android
application is now possible using
PrettyTest but we have to
renounce the benefits of testing (at least for now). See
test for further info about testing. To run the tests on your
desktop window you need the xdotool (see the Prerequisites
section)

To do

  • Write a complete game using the framework
  • Sound support
  • More tests

Credits

  • @jingweno for his cool build tool
    gotask

  • @eliasnaur for his Goandroid,
    the necessary condition for this work

  • @aded for patiently testing the pre-announcement release on his
    32bit broken machine.

License

See LICENSE.

Main metrics

Overview
Name With Ownerremogatto/mandala
Primary LanguageGo
Program languageGo (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2014-01-09 18:01:43
Pushed At2019-02-19 01:32:15
Last Commit At2014-10-08 17:18:34
Release Count0
用户参与
Stargazers Count619
Watchers Count53
Fork Count46
Commits Count73
Has Issues Enabled
Issues Count10
Issue Open Count5
Pull Requests Count4
Pull Requests Open Count1
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private