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?
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With