Import lib with multiple flavor - android

I have a lib with this flavors:
flavorDimensions "dim"
productFlavors {
nocustomer {
versionNameSuffix "-nocustomer"
dimension = "dim"
}
customer001 {
versionNameSuffix "-customer001"
dimension = "dim"
}
}
My build produce this file:
How to use my library with different flavors?
Example: i want to build an app that use nocustomer flavor. What should i write on gradle app file? Which library to include?

Related

How to generate multi flavor apk by selectively bundling the dependency library?

My android app depends on multiple android library (say A,B,C,D). I would like to generate different apks out of them say apk1 needs to consume only on A,B and apk2 needs to consume B,C.
I've explored the option of Android's product flavor concept by doing something like this,
android {
...
defaultConfig {...}
buildTypes {
debug{...}
release{...}
}
// Specifies one flavor dimension.
flavorDimensions "version"
productFlavors {
demo {
// Assigns this product flavor to the "version" flavor dimension.
// If you are using only one dimension, this property is optional,
// and the plugin automatically assigns all the module's flavors to
// that dimension.
dimension "version"
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
full {
dimension "version"
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
}
Now it's generating apks with multiple products but it is including all libraries for each flavor. How can I avoid this?
Use flavor-specific directives for your dependencies. Instead of implementation, for example, you would use demoImplementation and fullImplementation. The demo builds would include the demoImplementation dependencies, while full builds would include the fullImplementation dependencies.
The documentation page that you linked to shows an example, using a free flavor:
dependencies {
// Adds the local "mylibrary" module as a dependency to the "free" flavor.
freeImplementation project(":mylibrary")
// Adds a remote binary dependency only for local tests.
testImplementation 'junit:junit:4.12'
// Adds a remote binary dependency only for the instrumented test APK.
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

How to include a dependency in an Android gradle file based on flavorDimension?

I have an Android project with 5 flavors and 2 flavorDimensions.
See Below:
flavorDimensions "env", "device"
productFlavors {
dev {
applicationIdSuffix ".dev"
dimension "env"
}
staging {
applicationIdSuffix ".staging"
dimension "env"
}
prod {
applicationIdSuffix ""
dimension "env"
}
amazon {
dimension "device"
}
google {
dimension "device"
}
}
Is there a way to only include a dependency to one flavorDimension instead of just one flavor? Basically I have a dependency I only want included in googleDev, googleStaging, and googleProd (but not the amazon dimension)
Is there an easy way to do this without repeating each dependency 3 times?

Different signingConfig in multi-dimensional build flavors

Small example will describe the case:
flavorDimensions 'shape', 'api'
productFlavors {
fruit {
dimension "shape"
}
vegtable {
dimension "shape"
}
production {
dimension "api"
}
development {
dimension "api"
}
}
Task:
I need to keep different signing config for fruitProduction and fruitDevelopment flavors.
I have researched the gradle doc and I have not found the suitable task where I can override the config for special flavor.

Android | Can't build multi flavorDimension

I have multi dimensionFlavor as:
flavorDimensions "app", "endpoint"
productFlavors {
ph {
applicationIdSuffix ".app1"
dimension "app"
}
pac {
applicationIdSuffix ".app2"
dimension "app"
}
production {
dimension "endpoint"
// applicationIdSuffix ".production"
}
staging {
dimension "endpoint"
// applicationIdSuffix ".staging"
}
}
But I want the application id to have both the app and env name. like: com.company.application.app1.staging
And then comes the confusion in the directory structure to put the google-services.json separately for each package name.
I've tried like app/src/app1Staging/google-services.json
But it fails in the build.
google-services.json should be put under assets directory and accessed via AssetManager, something like AssetManager assetMgr = activity.getAssets();
And the paths should be organised according to your build flavors, e.g.
app/src/staging/assets/google-services.json

Android Studio 3.0 Flavor Dimension Issue

Upgraded to Studio Canary build. My previous project of Telegram Messenger is giving following error.
Error:All flavors must now belong to a named flavor dimension. The flavor 'armv7' is not assigned to a flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
What should I do? I have already seen that link but couldn't understand what to do. I have 3 build variants now, release,debug and foss.
If you don't really need the mechanism, just specify a random flavor dimension in your build.gradle or build.gradle.kts:
android {
...
flavorDimensions("default")
...
}
For more information, check the migration guide
After trying and reading carefully, I solved it myself.
Solution is to add the following line in build.gradle.
flavorDimensions "versionCode"
android {
compileSdkVersion 24
.....
flavorDimensions "versionCode"
}
Here you can resolve this issue, you need to add flavorDimension with productFlavors's name and need to define dimension as well, see below example and for more information see here https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
flavorDimensions 'yourAppName' //here defined dimensions
productFlavors {
production {
dimension 'yourAppName' //you just need to add this line
//here you no need to write applicationIdSuffix because by default it will point to your app package which is also available inside manifest.xml file.
}
staging {
dimension 'yourAppName' //added here also
applicationIdSuffix ".staging"//(.staging) will be added after your default package name.
//or you can also use applicationId="your_package_name.staging" instead of applicationIdSuffix but remember if you are using applicationId then You have to mention full package name.
//versionNameSuffix "-staging"
}
develop {
dimension 'yourAppName' //add here too
applicationIdSuffix ".develop"
//versionNameSuffix "-develop"
}
If you want not to use dimensions you should use this line
android {
compileSdkVersion 24
...
flavorDimensions "default"
...
}
but if you want ti use dimensions you should declare your dimension name first and then use this name after
THIS example is from the documentations:
android {
...
buildTypes {
debug {...}
release {...}
}
// Specifies the flavor dimensions you want to use. The order in which you
// list each dimension determines its priority, from highest to lowest,
// when Gradle merges variant sources and configurations. You must assign
// each product flavor you configure to one of the flavor dimensions.
flavorDimensions "api", "mode"
productFlavors {
demo {
// Assigns this product flavor to the "mode" flavor dimension.
dimension "mode"
...
}
full {
dimension "mode"
...
}
// Configurations in the "api" product flavors override those in "mode"
// flavors and the defaultConfig block. Gradle determines the priority
// between flavor dimensions based on the order in which they appear next
// to the flavorDimensions property above--the first dimension has a higher
// priority than the second, and so on.
minApi24 {
dimension "api"
minSdkVersion 24
// To ensure the target device receives the version of the app with
// the highest compatible API level, assign version codes in increasing
// value with API level. To learn more about assigning version codes to
// support app updates and uploading to Google Play, read Multiple APK Support
versionCode 30000 + android.defaultConfig.versionCode
versionNameSuffix "-minApi24"
...
}
minApi23 {
dimension "api"
minSdkVersion 23
versionCode 20000 + android.defaultConfig.versionCode
versionNameSuffix "-minApi23"
...
}
minApi21 {
dimension "api"
minSdkVersion 21
versionCode 10000 + android.defaultConfig.versionCode
versionNameSuffix "-minApi21"
...
}
}
}
...
I have used flavorDimensions for my application in build.gradle (Module: app)
flavorDimensions "tier"
productFlavors {
production {
flavorDimensions "tier"
//manifestPlaceholders = [appName: APP_NAME]
//signingConfig signingConfigs.config
}
staging {
flavorDimensions "tier"
//manifestPlaceholders = [appName: APP_NAME_STAGING]
//applicationIdSuffix ".staging"
//versionNameSuffix "-staging"
//signingConfig signingConfigs.config
}
}
Check this link for more info
// Specifies two flavor dimensions.
flavorDimensions "tier", "minApi"
productFlavors {
free {
// Assigns this product flavor to the "tier" flavor dimension. Specifying
// this property is optional if you are using only one dimension.
dimension "tier"
...
}
paid {
dimension "tier"
...
}
minApi23 {
dimension "minApi"
...
}
minApi18 {
dimension "minApi"
...
}
}
in KotlinDSL you can use like this :
flavorDimensions ("PlaceApp")
productFlavors {
create("tapsi") {
setDimension("PlaceApp")
buildConfigField("String", "API_BASE_URL", "https://xxx/x/x/")
}
}
If you have simple flavors (free/pro, demo/full etc.) then add to build.gradle file:
android {
...
flavorDimensions "version"
productFlavors {
free{
dimension "version"
...
}
pro{
dimension "version"
...
}
}
By dimensions you can create "flavors in flavors". Read more.

Categories

Resources