Cloning application sample

The HelloClonedWorld example

NeoMAD comes with an example application demonstrating this functionality : HelloClonedWorld.

The code is based on the HelloWorld project with additions allowing different applications using conditional coding to be produced.

The URS file

<urs xmlns:xsi=""
      <description>HelloClonedWord application example.</description>
   <binaryname filename="${BINARY_NAME}" />

Differences with the HelloWorld project are the addition of constants that will be computed according to the arguments provided to the command line (see ???).

HelloWorld and HelloWorldScreen classes

These classes are almost the same as those of the HelloWorld project except for HelloWorldScreen where we set the screen background color. The value of the background color will be computed in the constants file.

// set the background color of the layout

The Constants class

In this class we will compute all values allowing us to build different applications.

We first define a constant that determines the background color of the application:

/* Application background color **/

Then we define the constants used in the URS file:

/* Application specific resources folder **/
public static String RES_FOLDER;

/* Application identifier **/
public static String APP_ID;

/* Application name **/
public static String APP_NAME;

/* Application binary name **/
public static String BINARY_NAME;

Then we define boolean constants that will determine the application’s identity and we compute the previously declared variables:

/* When specified with -d option, sets the
 * application "red" or "green Default is "blue" **/
public static boolean RED = false;
public static boolean GREEN = false;

/* The static block allows us to compute
 * values of static variables **/
static {
   if (GREEN){
      RES_FOLDER = "green";
      APP_ID = "hellogreenworld";
      APP_NAME = "HelloGreenWorld";

   } else if (RED) {
      RES_FOLDER = "red";
      APP_ID = "helloredworld";
      APP_NAME = "HelloRedWorld";

   } else {
      RES_FOLDER = "blue";
      APP_ID = "helloblueworld";
      APP_NAME = "HelloBlueWorld";

   /* The default value for BINARY_NAME is computed with the
    * Let’s put the APP_NAME in it to distinguish our applications
    * This name must be computed after APP_NAME has been computed

Building the project

By using the correct build parameters, we are now able to produce different applications sharing the same source code but with different resources.

For instance, for the Android target, the following build commands:

neomad -t ANDROID -l 1 HelloClonedWorld.urs
neomad -t ANDROID -l 1 -d RED=true HelloClonedWorld.urs
neomad -t ANDROID -l 1 -d GREEN=true HelloClonedWorld.urs

will produce the following binaries:



With this sample application we demonstrate the power and efficiency of conditional coding with the use of the applicationidentifier tag.

By giving different versions of the application a different name and package name, we make sure that those applications will be identified by all platform systems as different and can therefore be installed on the same device without any conflict.

In this example, we only varied the project resources, but, according to your needs, you can also change classes, methods or whatever else you want.