6

I wanted to implement a new dynamic feature module in an existing app but had to give up due to product flavor problems.

The example code can be found here. https://github.com/henningBunk/dynamic_feature_problem

I have three modules:

  1. app. The main module of the app. It has two product flavors:

store: amazon and google
pay_status: free and pro

Resulting in four combinations: amazonFree, amazonPro, googleFree and googlePro

It depends on lib and lists dynamic_feature as a dynamic feature.

  1. lib. A library module, app and dynamic_feature depend on this module. lib only has the pay_status flavor. So when I build eg. the App as the googleFree flavor, lib will build it's free flavor.

  2. dynamic_feature. The new feature which shall be a dynmic feature. This module should not have any flavors. It depends on app and lib.

The three gradle files, reduced to product flavors and dependecies look like this:

App module build.gradle:

apply plugin: 'com.android.application'

android {
    dynamicFeatures = [":faq"]

    flavorDimensions "store", "pay_status"

    productFlavors {
        google { dimension "store" }
        amazon { dimension "store" }

        free { dimension "pay_status" }
        pro { dimension "pay_status" }
    }
}
dependencies {
    implementation project(':lib')
}

Lib module build.gradle:

apply plugin: 'com.android.library'

android {
    flavorDimensions "pay_status"

    productFlavors {
        free { dimension "pay_status" }
        pro { dimension "pay_status" }
    }
}

dependencies {
}

Dynamic feature module build.gradle:

apply plugin: 'com.android.dynamic-feature'

android {}

dependencies {
    implementation project(':app')
    implementation project(':lib')
}

This results in the error:

ERROR: Unable to resolve dependency for ':dynamic_feature@debug/compileClasspath': Could not resolve project :app.
Show Details
Affected Modules: dynamic_feature

So I read that the module dynamic_feature might need a missing dimension strategy. Adding

missingDimensionStrategy "store", "google"
missingDimensionStrategy "pay_status", "free"

to the dynamic_feature build.gradle into android.defaultConfig. This way I can build some flavors but not all of them:

enter image description here

Henning
  • 2,202
  • 1
  • 17
  • 38
  • Hi had the same issue and in my case I simply forgot to replace `apply plugin: 'com.android.feature'` with `apply plugin: 'com.android.dynamic-feature'` in one module.... – Vall0n Aug 06 '19 at 07:31
  • are you sure that we have the same problem? since i am already using ''com.android.dynamic-feature''. my problem lies in the different build variants. – Henning Sep 27 '19 at 20:41
  • Pretty sure... Maybe there is more than one way to get this error. – Vall0n Sep 30 '19 at 10:29

1 Answers1

2

I've found a solution but it's not satisfying. All build flavors must be implemented in the dynamic feature modul so all build flavors can actually be built.

missingDimensionStrategy does not work.

more infos here: https://proandroiddev.com/advanced-android-flavors-part-4-a-new-version-fc2ad80c01bb

Henning
  • 2,202
  • 1
  • 17
  • 38