HowTo: Android – Full and Lite Versions

A full working code example of this post is located on my GitHub account here: http://github.com/donnfelker/FullAndLiteVersionSharedLibrary

I’m in the process of completing an Android app for a client and they needed the ability to have full and lite versions of the same application. The lite version would be free and the full version would be for a small fee (say, $2.99).

The Android Market stores applications based upon their unique Java package name. Therefore you cannot have multiple apps with the same package name. Therefore you’re left to do one of two things-

  1. Create two Android projects and copy the code, altering/removing/etc whatever is needed for the Lite/Full Version.
  2. Manually recompile and change the package name each time you want to release each version.

Either way its a real PITA. Which is why I’m writing this post. If you’re application requires Lite and Full versions (or more) then you’ll love this below.

Android Project Libraries

Android now has project libraries. This solves the problem of above. I now have the following package structure -

  • com.example.myappAndroid Project Library - This is where my ENTIRE app lives. All the functionality for the FULL and LITE versions.
  • com.example.myapp.full - Android Application Project - This is a shell that contains graphics and resources needed for the full version only. Basically it’s a super lightweight shell.
  • com.example.myapp.lite - Android Application Project – This is another shell that contains nothing but graphics and resources needed for the lite version. Again, its a super lightweight shell.

How To Determine Lite vs. Full

In the com.example.myapp, I have an Application object that derives from the Android Application object. In this part of the app I check to see the package name contains the word “lite”. If so, then the app is running under a lite version. Here’s the code:


return getPackageName().toLowerCase().contains("lite");</pre>

Whats Happening Here? The library project takes on the package name of the project that is referencing it. Therefore at runtime, the package name equates to-

com.example.myapp.lite

Therefore I know that I’m running under the context of my LITE app. I can now disable/enable a feature based upon that knowledge.

Conclusion

While this may be a quick and simple approach, it works. Now, inside of my main library (com.example.myapp), I can sprinkle if statements all over the place to determine if the app is the full or lite version. That way I can share a common code base and not have to worry about maintaining different, yet similar code bases.

Downloads

Download a full working example here

Android Dev Digest

Get the best Android Developer posts delivered weekly to your inbox.

Don't worry, I wont spam (I hate that stuff too).

  • Pingback: Android Library Project Reference Not Showing « this.Reflect()

  • abedross

    How did you create the FooLite and FooFull projects? Can you please provide steps you took.

  • Shimbawa

    Thanks for this great example !
    I would like to add a precision: (and answer to abedross)
    - You first make your project as library project: project properties/android/library/check “is library”
    - Then create two android project, with library reference: project properties/android/library/add, then select your library project.
    - Then for each two projects, add the library to build path: project properties / java build path / projects / add / select your library project

  • droidnip

    Genius. Thanks for this.

  • Pingback: Multiple Versions of the Same Android App - binary calculator

  • http://twitter.com/etarasoff Eric Tarasoff

    That was EXACTLY what I needed. Thanks so much!

  • Vollkoff

    If you create the project lite/full projects don’t forget to remove the main.xml, otherwise the ids will not get created but everything else in the R file is ok…

  • http://www.best-registrycleaner.net Best Registry Cleaner

    The Android Market stores applications based upon their unique Java package name.

  • Michael Gunderson

    Did you run into any issues with proguard? After I implemented your examples, proguard is completely busted, saying that the output jar is empty.

  • http://blog.donnfelker.com Donn Felker

    Michael,

    I wrote this before progaurd was used in ADT, so I’m not sure. Android’s
    error messages are not exactly the most helpful, unfortunately.

  • Bobetko

    Well. It’s all nice, but how do you force library recompiling when you are compiling full or lite projects? I have to do Project > Clean > MyLib in order to do so… very unfortunate… any solutions? 

  • bitowl

    Add your library project to the build path.

    Do a right click on your project -> “Properties” -> “Java Build Path” -> “Projects” -> “Add” .

    Then it should be automaticly compiled if you compile the lite/full project

  • bitowl

    I made my own tutorial how to do this just with the main project and a lite project.

    check it out:
    http://bitowl.wordpress.com/2011/07/06/tutorial-how-to-make-full-and-lite-versions/

  • deepak patil

    how to run free and paid  application on emulator

  • Yangzhifang2006

    私たちは今まで、語る春トレンドのハンドバッグの明らかなように、がたくさんあります。私たちを持った コーチ アウトレットcoach バッグコーチ アウトレット、今日私はあなたに教えるのはもうひとつ傾向;花卉の模様が入っている。私たちは普段はこのコーチはコーチ バッグコーチの財布がなくて、しかし私はこのpurseblogの特徴がありす。コーチ 財布コーチ サングラスコーチ トート

  • http://profiles.google.com/fahadayaz Fahad Ayaz

    Does this still work? I can’t seem to get it working. The app force closes on opening. I’m trying it in Android 4.0 in the emulator (though it did the same in the 2.2 emulator).

  • Tos

    This solution looks perfect.
    I can’t wait to try it !

  • http://www.outsource-website-development.com/ outsource development

    Valuable information for all. And of course nice review about the application. It contains truly information. Your website is very useful. Thanks for sharing. Looking forward to more!

  • Coach Factory Outlet

    It’s good to see this information in your post

  • Coach Factory Outlet
  • Anonymous

    football boots comfortable and cheap
    football shoes designer bags Come surprise
    nike air max ltd good  trend  cheap
    gucci sunglasses Do not miss the nike-low prices
    gucci outlet online discount designer shoes
    gucci outlet 2012 is the master of them
    wholesale coach The new discount
    air max shoes Business casual bag cheap
    coach purses on sale Boutique explosion models
    wholesale coach The new discount fashion
    cheap basketball jerseys See this beautiful bag
    wholesale gucci shoes Affordable surprise bag
    discount gucci online Come to see the lowest package
    cheap authentic nfl jerseys online Fashion accessories boutique

  • Howard

    Thanks for this great tutorial, but I got this: Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED wile compiling. Any solutioin?

  • Nicolas LE BROZEC

     Hi there,

    I found your very good advice on handling lite and full versions but I have a few questions:
    - What do you put in your full/lite project files ?
    - How do you run the full/lite versions ?
    - Where are located the resources ?

    Thanks for your help.

  • Bajrang

    As described above we will have two apks to publish one for free and one for paid. Now user has installed free version and want to upgrade it with paid version. How will we handle this case?

  • nil

    Nice approach, is there a way we can restore user data from Lite App to Full as both being individual apps??

  • oolala

    Thanks for this. Great work.

  • Thomas

    After three years, this article still has MUCH value, as all the other possibilities have seen are “PITA”, as you said! :)

    Thanks a million! :)