Switching trial and pro builds with android apps in Eclipse: how to make it less painful?
Asked Answered
E

1

14

I have an application for Android which comes in two forms: a trial version and a paid "pro" version. The two versions coexists in Android Market and have different package names (let's call them com.app.trial and com.app.pro). They share the same codebase. When I have to switch between trial and pro builds in Eclispe, I have to spend no less than 20 minutes each time editing the code to make it build the correct version. My procedure looks like this:

  1. Rename package name in AndroidManifest.xml (also rename app versionName, and versionCode).

  2. Click on main package name "com.app.pro" (if pro was the lastest build and now I want to make a trial build) and select Refactor->Rename (check 'Update references' and 'Rename subpackages') and let Eclipse do the renaming.

  3. After this comes the hard part: in my code many files still import the "old" package name, "com.app.pro" instead of being automatically changed to "com.app.trial". In some cases Eclipse adds those references during the renaming, for no apparent reasons (there are no references to this specific package from within a given Java file). I have to manually edit all the instances.

My question is:

How do I make this procedure less time consuming? I also have been using NetBeans where there's a handy support for #ifdefs (aka Abilities) which really makes switching between builds a breeze. Eclipse unfortunately has no support (at least no buil-in support) for #ifdefs.

Any suggestions would be greatly appreciated.

P.S. For the reference I am using Eclipse Ganymede version 3.4.2 but also tried a newer version, it does the same.

Exuberate answered 26/3, 2011 at 17:28 Comment(1)
I posted a step by step answer on another thread here:[Maintaining both free and pro versions of an application][1] [1]: #2529562Melise
S
22

A great solution for this is to split your applications into three projects :

  • One library project, that will contain all common code
    • actually, creating two versions (lite and paid) of one application is one of the common scenarios this page is talking about ;-)
  • One project for the trial version,
  • and one project for the pro version.

Each trial and pro version will :

  • Reference the library project (that contains almost all code)
  • Define what is specific to the trial or pro version (like manifest, some strings, some additional code, ...)

With that, building the trial or the pro version is as simple as building one project, or the other : no need to change anything !


A couple of links that might help :

Shellishellie answered 26/3, 2011 at 17:32 Comment(2)
It is an option, but I was looking for suggestions how to make Eclipse rename the import statements when it does the refactoring. This is what I was expecting to happen, but no luck.Exuberate
Well, once the library project is set, no need to refactor anything each time you want to build one of the applications projects -- at worst, you'll have to do some search and replace once, when setting up the library project (so, a bit of pain once -- maybe it'll take you half an hour, top) ;; but, after that, just build each project that references the library ;-) (I'm doing this for a project of mine, and it works pretty well : building each app project is a matter of a couple of clicks, and i don't have to rename anything)Shellishellie

© 2022 - 2024 — McMap. All rights reserved.