1

I am trying to use the benefit of install-time dynamic delivery using country-specific condition. As per this doc Google Play does provide a way to give condition based on country. To make use of this I created 2 feature modules other than base module.

Module 1: This module has an implementation which is Philippines specific. So I modified the manifest of this module to look something like this -

<dist:module
        dist:instant="false"
        dist:title="@string/title_dynamicfeature">
    <dist:delivery>
        <dist:install-time>
            <dist:conditions>
                <dist:user-countries dist:include="true">
                    <dist:country dist:code="PH" />
                </dist:user-countries>
            </dist:conditions>
        </dist:install-time>
    </dist:delivery>
    <dist:fusing dist:include="true" />
</dist:module>

Module 2: This module has an implementation which is Mexico specific. So I modified the manifest of this module to look something like this -

<dist:module
        dist:instant="false"
        dist:title="@string/title_dynamicfeature">
    <dist:delivery>
        <dist:install-time>
            <dist:conditions>
                <dist:user-countries dist:include="true">
                    <dist:country dist:code="MX" />
                </dist:user-countries>
            </dist:conditions>
        </dist:install-time>
    </dist:delivery>
    <dist:fusing dist:include="true" />
</dist:module>

In the base module (app), I have written code to get country-specific implementation using reflection assuming that at a time only one country would be applicable. The code is like this -

private fun provideSharedFeature(): SharedFeature {
    val sharedFeatures = arrayOf(
        getClassInstance("com.jai.dynamicfeature.SharedFeaturePH"),
        getClassInstance("com.jai.dynamicfeature.SharedFeatureMX")
    ).filterNotNull()
    if (sharedFeatures.size > 1) {
        throw IllegalStateException("More than one feature module installed")
    } else if (sharedFeatures.isEmpty()) {
        throw IllegalStateException("No feature module installed")
    }

    return sharedFeatures[0]
}

This code works fine when I run locally since which module to build need to given in build configuration, but this fails when I download the app using Google Play. The app crashes with message "No feature module installed" which means none of the modules are provided.

Is there any other way through which I can achieve this?

1 Answers1

0

Shouldn't you put if (sharedFeatures.size > 0) ? You can only have MX or PH. Secondly, what is the country billing address of your testing device ?

Laurent Russier
  • 658
  • 5
  • 24