3

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.

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
  • Checkout this post: http://stackoverflow.com/questions/10569760/android-how-do-i-dynamically-set-the-package-name-at-build-time-for-an-open-so/10569893#10569893 where I answered a similar question – Matt Wolfe Nov 28 '12 at 06:11

3 Answers3

4

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.

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
  • Wow! I was thinking of creating some custom precompiler to automate this refactoring. But these 4 steps are the perfect solution! Thanks a lot! – Scrat Jul 19 '13 at 15:06
  • Hi: First wanted to say great answer. My question: Do you have a way to deploy easily to the apps to the Google play without all the hassle of uploading the apk/aab? Which CI/CD do you use? does it have a control system which just send the built app to the play store? – helenakohan Jun 05 '21 at 06:59
  • @helenakohan I only do this for five apps total, so I just manually upload them one by one and don't have a special system. If you have 20+ apps, you'll have to look into how to streamline this more. – Ethan Allen Jul 16 '21 at 18:14
1

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.

Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141
  • "and a little re-factoring in your code file due to base package name changed" - Can you elaborate? When I change the package name it looks like nearly every file has to be changed. Is there some automated way to change them all? – Ethan Allen Nov 29 '12 at 06:12
0

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

chairam
  • 335
  • 5
  • 12