Android and Eclipse 2 different versions of the same application

Hello, I'm starting an Android developer using windows and the eclipse development environment to develop Java applications for Android. I published one game, but there is a free version of the game and a paid version. The google market insists that different versions should have different package names. So far I have been refactoring a package with two different names and changing the import of the resource R file every time I create different versions. The code is 99% the same for both versions. Is there a better way?

+7
android eclipse
source share
2 answers

You have various discussions on this issue here and there , but basically this solution is like duplicating a project.

For example (not based on eclipse):

It is difficult to answer this, since we do not know what the difference is between free and non-free versions of your application.

I am going to suggest that differences can be handled by some kind of global free / non-free flag. By this, I mean that the same code will contain both versions of the application, and which parts are included or will be used will depend on some open static data element somewhere:

if (SomeClass.IS_PAID_APP) { // add more stuff to menu, etc. } 

If you can organize your application this way, you only need one code base.
Ask him to create his application one way (free or paid, of your choice) and with the appropriate package in the manifest for this version of the application.
Then add an Ant task that does the following:

  • Makes a copy of the project tree of your project in a temporary location
  • Switch the copy of the manifest to the new package name using search and replace
  • Switch all import statements for your old version of package R to the new package, again through search and replace, and again to the copy, not your original
  • Change your IS_PAID_APP (or something else) to the opposite value (search and replace in copy)
  • Builds Ant for a copy of the project
  • Copies binaries from this assembly to the main bin / directory project under a specific name (so that it does not compress your other copy of the APK)
  • Deletes a copy of the tree made in step # 1

If Java had a pre-processor, that would be a little easier. However, the basic technique that I described above has been used for several decades. This is awkward, but it works, and that means you only have one set of source code. Please note that the Ant <replace> task will perfectly process your material for search and replace.

+2
source share

This is one of the drawbacks of the Android Market, although I understand why they did it. This is just not intended for the free and paid versions of your application (they claim that a 24-hour return policy is what it is needed for, but is instead used for piracy) -

In any case, the easiest way is to write Ant build script (or any scripting language you use). Replace your package name search with all .xml and .java files. Then build your application. Refactoring your code hurts more than it costs IMHO ...

+1
source share

All Articles