6

I am trying to find the best method for white labeling an Android application. Basically I want to be able to build multiple versions of almost the same app, each version will have different resources (e.g. drawable icons, colors, etc.) but they will share a lot of the code base. Some of the apps will have additional features as well, so they won't just be clones of each other.

One method I have thought about is separating the shared code into a library, but the issue there is that some of the shared code includes activities so I'm not sure how the resources could be changed in each app.

Another method would be clone and own, but then any bugs or changes in one repository would have to be applied to the other.

Are there any other options? What is the best practice for sharing code, including activities, some resources, and other regular java classes, between two Android apps?

Zachary Sweigart
  • 1,051
  • 9
  • 23

1 Answers1

13

What is the best practice for sharing code, including activities, some resources, and other regular java classes, between two Android apps?

With Android Studio and Gradle for Android, white-labeling can be just a matter of setting up product flavors per customer in that one project. Your common code and default resources go in src/main/. Your additional code and resource overrides go in src/whateverNameYouGiveYourFlavorForTheCustomer/. Then, whether from Android Studio (Build Variants view, docked on the left) or from the command line, you can build the different app outputs for each customer-specific flavor.

You are also welcome to go the library route. Resources of the same name defined in an app override the resources from a library.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Can two white labels be installed simultaneously from play store? I have one white label app installed on my device but when I try to download another one, it returns error and says "It can't be installed". Any pointers? – Misha Bhardwaj Mar 23 '17 at 04:56
  • @MishaBhardwaj: The apps would need separate application IDs, which you can set in Gradle. The apps would also need to ensure that all content providers have unique authority strings (e.g., based on the application ID). And on Android 5.0+, they either should not define new permissions (`` elements) or should be signed by the same production keystore. LogCat may give you some clues as to why the install failed in your particular case. – CommonsWare Mar 23 '17 at 11:53
  • How to manage the codebase? How do I track which version (or changeset in version control) is used for which version for certain customer? – muthuraj Nov 21 '17 at 13:04
  • @muthuraj: That is well outside the scope of this question and answer. The approach outlined here works fine when all customers are on the same version, and when you ship a new version of the app, you are shipping that to all customers. If you will have different customers on different versions of the app, product flavors alone may not be sufficient. I recommend that you ask a separate Stack Overflow question for that topic. – CommonsWare Nov 21 '17 at 13:14
  • @CommonsWare Thanks. I asked as a separate [question](https://stackoverflow.com/questions/47428020/how-to-manage-codebase-for-whitelabel-apps-for-android) . – muthuraj Nov 22 '17 at 06:19
  • This seems like a heavy weight solution. Works ok for a handful of flavors. But would fall down, I think, if you had dozens or hundreds of flavors. E.g. a radio station app. It could be identical except for some skin resources and a few configuration settings. Isn't there a way to drive that process from a database? For other types of apps, e.g. corporate in-house deployments, what is the best way to distribute white label apps privately (i.e. _not_ on the public app stores but not forcing everyone to manually deal with APK files)? Same questions apply for iOS apps, of course. – Charlie Reitzel Aug 02 '19 at 16:37
  • @CharlieReitzel: "Isn't there a way to drive that process from a database?" -- there is nothing "out of the box" for that, probably because that is a rather atypical scenario. IMHO, that would be far more complicated than using product flavors, but I certainly can't rule out the need for something like that. – CommonsWare Aug 02 '19 at 17:07
  • The use case is any SaaS enterprise application with a mobile app component. So, a fairly normal case, I think. If you are selling to small-to-medium sized businesses, you don't want to have to release new software for every sale. You want a database update to take care of it. I think Apple's MDM might handle it on the iOS side. Looking into it. Not sure about the Android side. Want to avoid requiring users to disable signature checks on their phones to require installing app. – Charlie Reitzel Aug 04 '19 at 18:56
  • @CharlieReitzel: "So, a fairly normal case, I think" -- not really. Frankly, I wish it were. "If you are selling to small-to-medium sized businesses, you don't want to have to release new software for every sale" -- then don't. Microsoft does not create customized copies of Word for each small-to-medium sized business, for example. You're the one who wants to provide customized copies of apps for each sale, and neither the Android nor the Google Play model are really set up for that. – CommonsWare Aug 04 '19 at 19:02
  • @CharlieReitzel: "Want to avoid requiring users to disable signature checks on their phones to require installing app" -- that's never been a thing in Android. If you are not distributing through the device's built-in app distribution channel (e.g., Google Play), users would need to allow something to install apps, to be able to install yours. And on older devices, that's an all-or-nothing switch (either anything can request to install an app, or nothing can). On Android 8.0+, users can grant request-to-install permissions on a per-app basis (e.g., Chrome can, J Random App can't). – CommonsWare Aug 04 '19 at 19:04
  • 1
    @CommonsWare I take your point re Word. But that's not what I'm talking about. if you are delivering an Enterprise app (Word isn't really that) requiring login based on the company's Active Directory (or equivalent), then some binding is required (you don't want everyone to have to manually configure this stuff). Some skinning helps folks know they have go the right app. There are a fair number of apps out there that do this. I'm wondering how they work it. I probably need to compose a new question. Not sure the best place to post it. Thanks for responding. – Charlie Reitzel Aug 05 '19 at 23:04