mnit and its Android variant,
mnit_android, has been added to the language library, Nit support compiling to the Android platform.
So you want a software product line?
A software product line is a set of applications sharing a commom subset of features (or code when in development). We rely on this idea to create cross-platform applications in Nit with
mnit. In the case where you target a specific platform (forever), you don't have to bother with it, write a single application and skip this section.
We begin by illustrating an usage of software product line using the example of the Dino project. It is found in the Nit repository under examples/mnit_dino/.
The Dino project has 5 modules shared across all platforms:
The higher level modules is
game_logic, it is completely independent of any platform, graphic framework and application framework. It can be used to test the full logic using command line applications.
fancy_dinouse class refinement to introduce new services based on the graphic framework of
mnit. Separating business logic from the GUI is a good practice in any software. Class refinement just makes it easier and cleaner.
dinodescribes the application logic by implementing an
mnitapplication framework. With its importations, it unites all of the code shared between platforms. By itself, it cannot be compiled to a working application.
As products, the Dino project defines 2 main modules for the actual working applications:
dino_linuxis the Linux version of the game. Besides the shared code, it imports only
dino_androidis the Android version of the game. It imports
mnit_androidand defines behaviors specific to the Android platform. Most notably, the vibration from
All these 7 modules implement 2 products/applications. Plus, you could test the game logic using only
mnit rely on a similar structure for any cross-platform application.
Compiling the examples
Begin by installing the Android SDK and NDK. Update the environment variable PATH to include the path to the NDK and
make android in the root of the package. It will generate an APK in the
Now take a look at the
Makefile, the android rule is pretty straight forward. The Nit compiler detects the target plaform from the imported modules. Including the
mnit_android modules also import
android. The last one triggers the compilation to an APK instead of an executable.
Libraries compatible with Android
Classic Nit libraries
We'll divide the Nit libraries in 3 categories:
All Nit libraries implemented in pure Nit, can be used on Android. This includes most of the standard library,
Libraries wrapping external C libraries will work on Android only if they are available in the NDK. As of now, the Nit libraries
jvmare available. To see what extra libraries are available on Android and could be wrapped, take a look at the available C header in
Other libraries wrapping C libraries that are not available in the Android NDK will not work on Android. This includes
curses, etc. If needed, some of them can be ported to Android. As of now, only libpng is included in the generated projects. It is only used by
mnit_androidand is not directly available as a module.
Android specific services in Nit
The Nit library offers a few (but growing) number of libraries for the Android platform.
Many services are included in the
mnit_android module and are automatically made available to you:
- Load package assets using
- Access sensor data.
TODO add vibration when integrated
Frequently Asked Questions and Common Problems
On installing the application on some devices I get "Package file was not signed correctly"
Usually this error is caused by an incorrect version of jarsigner used by the developer. You must use the one from JDK 6, not 7.