Java – How do I make multiple Android applications from a single codebase?

How do I make multiple Android applications from a single codebase?… here is a solution to the problem.

How do I make multiple Android applications from a single codebase?

I’ve done this perfectly on iOS and now I need to use it on Android. I have a codebase that can create an infinite number of different apps with simple configuration file changes.

Each application is created based on a complex XML configuration file that I included in the resource. All I did was make a simple change in my strings.xml file, which points to the desired config file, which in turn makes my project a new standalone application. Very simple.

<string name="xmlconfig">nike-shoes</string>

But now that I’ve done that, how do I make changes so that each app is its own APK?

How to easily switch between apps (and uploadable apks) using one code base and one project. I’ve heard people say “use one library, then create a project for each library that contains it”, but this can get too complicated when you have more than 15 applications and they’re growing.

And I’ve also seen people say “why not just make one app, you can switch all apps within the app”, but that’s also irrelevant to my project and doesn’t make sense to my users. Unfortunately, I can’t explain more, but the short answer is that this won’t work either.

What I did on my iOS project was, I just changed the bundle ID, changed the code signing identity to match, changed the app name, and pointed to the new plist from my main Info.plist file. Bang! Brand new app. A few simple steps in less than a minute.

How do I do this using Eclipse/Java/Android? What is the easiest way?

A few steps will do, as long as I don’t mess up every file just to get it done.

Solution

I

think I’ll answer my own question here using Android Studio (2.2.3 when I type), doing the following:

  1. In your AndroidManifest file, click your package name (click the whatever part of com.myapp.what), and then press Shift+F6. Select Rename Package, and then rename it (without the com.myapp section). Do not do this for comments, strings, and text unless you need to. You need to approve the refactoring using the button at the bottom of the Android Studio window.

  2. Check your build.gradle file and make sure the applicationId under defaultConfig matches what you’ve changed.

  3. In your strings.xml file, change your app_name and other strings as needed to make your app your own.

It takes me about 1-2 minutes to have a brand new app. Hope others find this useful.

Related Problems and Solutions