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-
- Create two Android projects and copy the code, altering/removing/etc whatever is needed for the Lite/Full Version.
- 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.myapp – Android 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.
How did you create the FooLite and FooFull projects? Can you please provide steps you took.
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
Genius. Thanks for this.
That was EXACTLY what I needed. Thanks so much!
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…
The Android Market stores applications based upon their unique Java package name.
Did you run into any issues with proguard? After I implemented your examples, proguard is completely busted, saying that the output jar is empty.
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.
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?
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
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/
how to run free and paid application on emulator
私たちは今まで、語る春トレンドのハンドバッグの明らかなように、がたくさんあります。私たちを持った コーチ アウトレットとcoach バッグコーチ アウトレット、今日私はあなたに教えるのはもうひとつ傾向;花卉の模様が入っている。私たちは普段はこのコーチはコーチ バッグコーチの財布がなくて、しかし私はこのpurseblogの特徴がありす。コーチ 財布,コーチ サングラス,コーチ トート
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).
This solution looks perfect.
I can’t wait to try it !
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!
It’s good to see this information in your post
http://buycoachfactoryoutletsz.com
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
Thanks for this great tutorial, but I got this: Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED wile compiling. Any solutioin?
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.
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?
Nice approach, is there a way we can restore user data from Lite App to Full as both being individual apps??
Thanks for this. Great work.
After three years, this article still has MUCH value, as all the other possibilities have seen are “PITA”, as you said! 🙂
Thanks a million! 🙂
Thanks a lot for sharing this.
God bless 🙂
This article is excellent. Five years old, yet just as relevant as the day it was written.
Holy cow, it is five years old. There is a better way now. I need to update this. You should use build variants.
What package is being downloaded on phone trough google play? Is it lite or full package? Also, how can user, once purchased full version of app, get that download and it’s own updates. Because, I may change something for premium users and not for lite.
If you are using Android Studio you can use gradle build variants with different product flavors (full flavor and demo flavor for example). You can find more info with an example here: https://developer.android.com/tools/building/configuring-gradle.html