Handling free and paid versions of an app

So my app has two versions, free and paid. They’re 100% identical in features, but the free version has ads, the paid one doesn’t.

I’ve seen people maintain two branches or even repos for their apps, which involves doing pull requests between them all, messing around with icons and such. This seemed like a lot of effort, and prone to error, so I added some gulp tasks that handle config editing, building, signing, aligning and so forth for me.

If you’re keen to find out more, check out my blog post here: http://blog.davidgray.photography/handling-free-and-paid-versions-of-a-cordova-app/

Or jump straight to the code here: https://gist.github.com/Grayda/a51c6c55cc48f8a45dd6a26ca10894e2 . Pay attention to the required values, and edit the defaults!

Or if clicking links is not your thing:

The gulpfile (which should be edited and checked prior) uses xmldoc to load your config.xml file. Then another gulp task sets the name and ID accordingly. So if you run gulp build-android-free then set-free-vars is called first, which sets the widget id (i.e. the package ID) to “com.example.app.free” and the name (i.e. package name) to “Example App Free”. Once that’s been changed, set-free-icon is called and the icon icon_free.png is renamed to icon.png and sent to ionic resources. Finally, the APK is built by shelling out to cordova build android --release, signed by calling jarsigner and finally zipaligned.

As for the code inside my app, I installed the cordova-plugin-app-version plugin and then using ngCordova:

$cordovaAppVersion.getPackageName().then(function(name) {
    if (name == "com.example.app.free") {
      // Free version. Code to show ads goes here
    } else if (name == "com.example.app") {
      // Whatever you want here
    } else {
      // Package name can't be determined, or is different.

You could set a variable and use ng-if to hide non-free features, you could display a “please consider buying the paid version” message, the possibilities are limitless.

Hope this gets someone started in better maintaining different versions of their apps.