Ethan Allen
Ethan Allen

Reputation: 14835

How do I make multiple Android apps from a single code base?

I have done this with iOS perfectly and now I need it for Android. I have one codebase that can create unlimited different apps with a simple config file change.

Each app is created based on a complex XML config file that I included in the resources. All I make is one simple change in my strings.xml file and it points to the config file needed, which in turn makes this my project a new standalone app. Easy.

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

But now that I have done that, how do I make the change so each app is it's own APK?

How can I switch between apps (and uploadable apk's) easily with one codebase and one project. I have heard people say "use a library and then just create a project for each that includes it" but that gets overly complicated when you have 15+ apps and growing.

And I've also seen people say "why not just make one app where you can switch between them all within the app" but that also is irrelevant to my project and doesn't make sense to my users. I can't explain more than that unfortunately, but the short answer is that this won't work as well.

What I did on the iOS project I have is that I just change the Bundle ID, change the code signing identify to match, change the app name, and point to the new plist from within my main Info.plist file. BAM! Whole new app. A few simple steps that takes me less than a minute.

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

A few steps is fine, as long as I am not mucking with every file to get it done.

Upvotes: 3

Views: 2542

Answers (3)

Ethan Allen
Ethan Allen

Reputation: 14835

I figured I would answer my own question here using Android Studio (2.2.3 at the time I'm typing this), do the following:

  1. In your AndroidManifest file, click on your package name (click the whatever part of com.myapp.whatever) and then hit Shift+F6. Choose "Rename package" and then rename it (without the com.myapp part). Don't do it for comments, strings, and text unless needed. You'll need to approve the refactor with the button at the bottom of the Android Studio window.

  2. Check your build.gradle file and make sure your applicationId under defaultConfig matches what you changed it to.

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

Takes me about 1-2 minutes to have a whole new app. Hopefully someone else finds this useful.

Upvotes: 4

chairam
chairam

Reputation: 335

Convert your initial project in a library project, then reference to it from all other projects. This way you have a big advantage: all modification made to the library project are yet available in the other projects. Refernce: http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

Upvotes: 0

Chen Kinnrot
Chen Kinnrot

Reputation: 21015

All you need to do is change the package name in the manifest(and a little re-factoring in your code file due to base package name changed), and the next build will create a new App. If you want to maintain all your apps I would also recommend to create a branch for each app that will contain this change set. this way you can fix something and push it to all versions.

Lets say you change com.foo to com.foo.bar, then rebuild, all your R imports should be now added .bar, just find replace import com.foo.R to com.foo.bar.R, thats about it.

Upvotes: 1

Related Questions