Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Free/Paid versions of Application from same code

Tags:

android

So I'm coming down to release-time for my application. We plan on releasing two versions, a free ad-based play-to-unlock version, and a paid fully unlocked version. I have the code set up that I can simply set a flag on startup to enable/disable ads and lock/unlock all the features. So literally only one line of code will execute differently between these versions.

In order to release two separate applications, they require different package names, so my question is this: Is there an easy way to refactor my application's package name? Eclipse's refactoring tool doesn't resolve the generated R file, or any XML references in layout and manifest files. I've attempted to make a new project using the original as source, but I can't reference the assets and resources, and I'm looking to avoid duplicating any of my code and assets. It's not a huge pain to refactor it manually, but I feel there must be a better way to do it. Anybody have an elegant solution to this?

Edit/Answered:

For my situation I find it perfectly acceptable to just use Project -> Android Tools -> Rename Application Package. I wasn't aware this existed, and I feel like an idiot for posting this now. Thanks for everyone's answers and comments, feel free to vote this closed.

like image 518
LeffelMania Avatar asked Apr 08 '11 03:04

LeffelMania


People also ask

Can you code your own Android app?

You can download Android Studio 3.6 from the Android Studio page. Android Studio provides a complete IDE, including an advanced code editor and app templates. It also contains tools for development, debugging, testing, and performance that make it faster and easier to develop apps.

Can we get source code of any app?

Source code is available for most apps and websites. You can find it on the developer's website, or sometimes you can find it in the app's store. If you can't find it, or if you want to view it before downloading it, you can usually find a copy of the source code on the internet.

Can we make app in Android studio without coding?

To create a mobile app without coding, you need to use an app builder. These are tools that come with pre-programmed templates and features that you can use to edit and customize your app. Because the features in app builders are pre-made, you don't need to program them yourself.


2 Answers

It's very simple by using build.gradle in Android Studio. Read about productFlavors. It is a very usefull feature. Just simply add following lines in build.gradle:

productFlavors {     lite {         packageName = 'com.project.test.app'         versionCode 1         versionName '1.0.0'     }     pro {         packageName = 'com.project.testpro.app'         versionCode 1         versionName '1.0.0'     } } 

In this example I add two product flavors: first for lite version and second for full version. Each version has his own versionCode and versionName (for Google Play publication).

In code just check BuildConfig.FLAVOR:

if (BuildConfig.FLAVOR == "lite") {    // add some ads or restrict functionallity  } 

For running and testing on device use "Build Variants" tab in Android Studio to switch between versions: enter image description here

like image 79
Denis Avatar answered Oct 08 '22 13:10

Denis


Possibly a duplicate of Bulk Publishing of Android Apps.

Android Library projects will do this for you nicely. You'll end up with 1 library project and then a project for each edition (free/full) with those really just containing different resources like app icons and different manifests, which is where the package name will be varied.

Hope that helps. It has worked well for me.

like image 45
mmeyer Avatar answered Oct 08 '22 14:10

mmeyer