Skip to content
paddybyers edited this page Nov 25, 2011 · 3 revisions

Introduction

Anode supports native custom modules, or addons. These are shared libraries that satisfy node's ABI for loadable modules.

Overview

To simplify the building of addons, a framework is provided for building them using the Android NDK. The relevant source files are in anode/sdk/addon/. It should be possible to create addons that are portable at the source level, requiring the addition of only the Android makefiles to cross-compile for Android. As with building any native code for Android, consult the NDK documentation for details of the libraries available, and general porting considerations for native code.

The NDK will always define -DANDROID for both C and C++ sources, and this can be used for any conditionals that relate to Android.

To build the source using the NDK, two makefiles need to be created. Examples of these are provided for the "hello world" addon in anode/sdk/addon/sample/hello.

The main makefile is named Android.mk by convention, and it uses the NDK framework to declare the sources, flags, defines, etc. Refer to the main NDK documentation for how to set this file up; the sample gives some clues.

The second makefile, Application.mk, is simply required so that the NDK will build the library standalone - that is, not as part of a larger Android project. The Application.mk provided with the sample can simply be copied for each addon; or, referring to the NDK documentation, you could include multiple addons - ie multiple Android.mk files - in a single Application.mk.

Prerequisites

Check out the anode and node trees and build the node jni library as described in the build instructions. Addon projects can be built anywhere and do not need to be located in the anode source tree. However, some environment variables need to be set up so that the relevant headers and other resources can be found.

Set up the following environment variables: NODE_ROOT must point to the root of the node source tree. ANODE_ROOT must point to the root of the anode source tree. If the build instructions were followed, then:

export NODE_ROOT=<work dir>/node
export ANODE_ROOT=<work dir>/anode

Build the addon

cd into the top-level source directory containing the addon code (which must also contain the makefiles). The build with:

ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk

Refer to the documentation for the NDK to see more options for ndk-build.

Deployment

The addon can be deployed by copying (for example with adb push) it to the anode module directory on the target device. This is located in /data/data/org.meshpoint.anode/app/module/.

NOTE: you will only be able to push directly to this location on a rooted device (ie with ADB server running as root). This limitation will be remedied in a forthcoming release.

Clone this wiki locally