Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android build configurations for multiple customers

I have Android application that needs to be delivered to multiple customers. For every customer I have different graphics and configuration XML files which specify features and URLs.

At build time we should be able to specify the customer for which the application should be built. Then resources (like images and run-time configuration) appropriate for the specified client should be built into the app.

The project is build with Maven.

Any ideas?

like image 798
peceps Avatar asked Sep 26 '11 07:09

peceps


People also ask

What is build configuration in Android?

Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app. The Android plugin for Gradle works with the build toolkit to provide processes and configurable settings that are specific to building and testing Android applications.

What are build variants in Android?

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

What is productFlavors Android?

Product Flavors so what are they? Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.

What is BuildConfig flavor?

BuildConfig.FLAVOR gives you combined product flavor. So if you have only one flavor dimension: productFlavors { normal { } admin { } } Then you can just check it: if (BuildConfig. FLAVOR.


1 Answers

I ended up using maven profiles and 'renameManifestPackage' and 'resourceOverlayDirectory' properties of the android maven plugin.

The default res/ dir is overriden by 'resourceOverlayDirectory' specific for every customer.

It worked out great.

<!-- profile for zurich -->
<profile>
  <id>zurich</id>
  <properties>
    <customer>zurich</customer>
    <customerPackage>zurich.com</customerPackage>
    <customerResources>customers/${customer}/res</customerResources>
    <customerApkName>${customer}-${project.artifactId}</customerApkName>
  </properties>
</profile>

and in the build I have:

<build>
  <sourceDirectory>src</sourceDirectory>

  <!-- the name of the generated apk and jar -->
  <finalName>${customerApkName}-${project.version}</finalName>

  <pluginManagement>

    <plugins>

  <!-- customer specific manifest and package -->
  <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>maven-android-plugin</artifactId>
    <configuration>
      <renameManifestPackage>${customerPackage}</renameManifestPackage>
      <resourceOverlayDirectory>${customerResources}</resourceOverlayDirectory>
    </configuration>
  </plugin>

    </plugins>

  </pluginManagement>
like image 141
peceps Avatar answered Oct 08 '22 01:10

peceps