D
D
Denis2018-07-16 10:13:55
Android
Denis, 2018-07-16 10:13:55

How to properly assemble two apps using productFlavors in android?

Good day to all!
The customer needed to have two applications in google play, which literally differ only in where they make the request, icons and names.
I tried using productFlavors with something like this

flavorDimensions "application"
   
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "ru.local"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 30
        versionName '1.28'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        signingConfig signingConfigs.config
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
        agrodozorSengenta {
            applicationIdSuffix ".app1"
            dimension "application"
        }
        agrodozorStandart {
            applicationIdSuffix ".app2"
            dimension "application"
        }
    }

But this led to the fact that it is impossible to install both applications on the same device.
Please tell me what is the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2018-07-16
@lacredin

Specifically in my case, the problem was that I was using a ContentProvider that didn't take care of the unique name.
Once the name was dependent on the version of productFlavors, everything started working.
This is how the modified provider looks like

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="@string/provider_authorities"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_path">
            </meta-data>
        </provider>

I take @string/provider_authorities parameter from xml bound to productFlavors

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question