Freemium and paid app from same source code

Many times you want to create two or more applications from the same source code, in my case I wanted to create an app that has both a freemium version (with advertisement) and a paid one.

Development Process

  1. Usually I’ll start by creating a regular Android project and code my app just like any other app.
    Using a single project for development at least in the beginning eases the entire process.
  2. When I’m done with the full app, I’ll add my advertisement code:
    /**
     * If it is a light version show ads.
     */
    private void handleLightVersion() {
    	String isLight = getString(R.string.is_light);
    	if (isLight.equalsIgnoreCase("true")) {
    		// Look up the AdView as a resource and load a request.
    		AdView adView = (AdView)this.findViewById(R.id.adView);
    		AdRequest request = new AdRequest();
    		adView.loadAd(request);
    	}
    }
    

    Lines 5 and 6 do the magic, test to see if a specific string exists and get its value, if the value is true then show ads, otherwise don’t.

  3. Convert the project into a library project (see SDK).
  4. Add new regular project and add the library project as a reference (see SDK). Pay attention the name of the app package should be different than the one used in the library project (you can add ‘light’ suffix to the name).
  5. Under the android manifest make sure to add all the activities/services etc that you intend to use (usually all of them). Make sure to reference them with the correct package name (the one used in the library project).
  6. Under the strings.xml file add the string that indicates whether it is a light  version or not. In our case it is.
    <string name="is_light">true</string>
    
  7. Android will automatically know to merge the various resources together, now that is neat.
  8. Create another project this time for the one without advertisement, follow  steps 4-7, but this time change is_light to false.
    <string name="is_light">false</string>
    

Done.

Advertisements

Leave a comment

Filed under API

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s