2

I was ordered to deliver an app in 2 versions : one demo/light (limitted features) the other full (all features). I have a boolean in code which tells which one is running. They both run as expected in the simulator or on a test device (iOS and Android).

Now I want to distribute them. So I read that it was possible with XCode to define different targets corresponding to the light / full versions and with Eclipse it was possible to define the base project as a library and then create 2 projects also corresponding to the light / full versions.

Before I start messing around with my app project, is there a recommended way to achieve my goal with CodenameOne maybe via build hints that would change the app name and the boolean inside the code depending on a build hint value ?

EDIT 19/09/2016 (working methodology)

Following Shai's advices here are the steps I followed to generate a light version based on the full one (in case someone encounters the same case) :

  1. Under your IDE (Eclipse or whathever) copy and paste the base package in the src folder and rename it com.packageLIGHT.appName (simply append LIGHT to the package name, don't use underscore or space since it will be considered as an illegal character later by Apple)

=> So now in src folder you should have

src

|- com.packageLIGHT.appName

|- com.package.appName

  1. Then in com.packageLIGHT.appName remove all files except MyApp.java (aka the main file). In this file add import com.package.myApp.*;

    3.1. (ECLIPSE) In "Run/Run Configurations" menu copy the existing config and paste it as Simulator_MyAppLIGHT and in arguments change it to "com.packageLIGHT.myApp.MyApp".

    3.2. (NETBEANS) The "Run/Set Project Configuration" does not seem to work as expected since any configuration that might be selected leads to the same default behaviour. However applying step 6. and running the project in the simulator afterward has the expected result.

  2. Now you should be able to run both versions by running the different configurations.

  3. For iOS (not sure if it is also needed for Android) you have to generate another pair of provisioning files. So move the existing ones in iosCerts/FULL and use CN1 wizard to generate the "light" version provisioning files where you'll adapt the package name to match "com.packageLIGHT.myApp". Store the generated files in iosCerts/LIGHT. There is no need to overwrite the existing certificates (more on certificate here).

  4. Finally replace in "codenameone_settings.properties" the original package name with the "light" one for the lines codename1.ios.appid and codename1.packageName. Also change the iOS provisioning files to iosCerts/LIGHT or FULL depending of what you want to build.

  5. Now when you send the Android / iOS build to CN1 server it will build either the "light" version or the full one depending on what package is written in "codenameone_settings.properties".

Please note : if at step 6. you get NullPointerException on build.xml on line 469 (android build) or 344 (iOS build) which deals with certPassword="${codename1.android.keystorePassword} (android build) or appid="${codename1.ios.appid}" (iOS build) and you're using CN1 plugin version 1.0.0 20160812 under Eclipse then Shai's comment below may be worth it

Community
  • 1
  • 1
HelloWorld
  • 2,275
  • 18
  • 29

1 Answers1

2

If you want 2 distinct versions of the same app then you need 2 distinct packages since the thing that defines the app uniquely in the store is the app package. There are two common ways to do it:

  • Place functionality in cn1lib and build two apps
  • Build one app and just swap the codenameone_settings.properties file

The first one should be pretty clear but might be a bit painful to work with as you can't run the cn1lib and might run into issues debugging it.

The second one is actually rather simple. Create the main version of the app then add the package to the demo version and copy the main file there.

To run the demo version just change the package in the IDE "run settings".

Copy your codenameone_settings.properties to a separate file and just replace all the regular package names to the demo package names. When you want to build the "demo" version replace the codenameone_settings.propeties files with one another, you can automate that with a script obviously.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks! I applied the second one without success. My main version is at com.package.appName. I backed the codenameone_settings.properties up and replaced the original com.package.appName with com.package_LIGHT.appName. In Eclipse I did NOT need to "Run Configurations". Eventually I sent the Android build to CN1 but it failed due to `MyApp/src/main/java/com/package_LIGHT/appName/AppNameStub.java:23: error: cannot find symbol`. I understand why it fails, but how to avoid that ? The only way I see is to create a new Demo Project and copy paste the content of the main version. Did you mean that ? – HelloWorld Sep 16 '16 at 08:05
  • You need to have two main classes one under package and another under package_LIGHT. Notice that this can allow you to differentiate the logic of the two implementations and you can even reuse code by deriving one from the other – Shai Almog Sep 17 '16 at 05:41
  • Thanks for this piece of information. Until running both versions in the IDE everything works good. But then when I try to send ANdroid or iOS Build it fails (see my edits in the question) and furthermore I cannot open the "basics" menu from CN1 preferences. I put the exact steps I made and the error stack I get in the original question so that you can better understand what's happening. – HelloWorld Sep 18 '16 at 08:21
  • 1
    That means the properties aren't found as the elements aren't defined there. The issue of not getting into the basics section is something we fixed, it was triggered because of missing or broken icon.png – Shai Almog Sep 19 '16 at 05:24
  • OK the icon.png had a problem indeed (could not be opened by Gimp also). It was regenerated and the basics section can now be opened again. The build process also works flawlessly. II'll update the question so that people can find the full methodology step by step. Thanks a ton Shai! – HelloWorld Sep 19 '16 at 08:17
  • Package name (CFEBundleIdentifier indeed) cannot contain underscore. Otherwise it is not possible to build the app for iOS. I changed it in the question. – HelloWorld Sep 19 '16 at 10:03
  • Great, we probably need to validate against problematic package names like that – Shai Almog Sep 20 '16 at 04:01