Android Content Provider and Gradle productFlavours
Asked Answered
H

0

12

I have app which should have 2 flavours: free and paid. Separately both versions works perfectly. But when I want to install 2 of them at once I'm getting error: [INSTALL_FAILED_CONFLICTING_PROVIDER]. I've tried to change android:authorities and buildConfigField values to be totally different but It's doesn't change anything - app won't install. Also I've deleted provider declaration in main Android Manifest - nothing. Please help me.

My folders structure:

src
|- free
|   |- AndroidManifest.xml
|- main
|   |- all files and res catalogues (java, res, values etc.)
|   |- AndroidManifest.xml
|- premium
    |- AndroidManifest.cml

My gradle file:

apply plugin: 'com.android.application'


android {

compileSdkVersion 19
buildToolsVersion '20.0.0'

final PROVIDER_FREE = "com.example.free.contentprovider"
final PROVIDER_PRO = "com.example.pro.contentprovider"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 20
}
buildTypes {
    release {
        minifyEnabled false // new version
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
    free {
        applicationId "com.example.free"
        versionCode 141201004
        versionName "1.004"
        buildConfigField "String", "PROVIDER_AUTHORITY", "\"" + PROVIDER_FREE + "\""
    }
    premium {
        applicationId "com.example.pro"
        versionCode 141210001
        versionName "0.001 Pro"
        buildConfigField "String", "PROVIDER_AUTHORITY", "\"" + PROVIDER_PRO + "\""
    }
}
}

My content provider:

public class DatabaseContentProvider extends ContentProvider {
    public static final String AUTHORITY = BuildConfig.PROVIDER_AUTHORITY;
    ...
}

My free Android Manifest:

<provider
        android:name="com.example.tools.DatabaseContentProvider"
        android:authorities="com.example.free.contentprovider"
        android:exported="false"
        android:grantUriPermissions="true">
     <grant-uri-permission android:pathPattern=".*" />
</provider>

My premium Android Manifest:

<provider
        android:name="com.example.tools.DatabaseContentProvider"
        android:authorities="com.example.pro.contentprovider"
        android:exported="false"
        android:grantUriPermissions="true">
    <grant-uri-permission android:pathPattern=".*" />
</provider>
Hertha answered 8/12, 2014 at 13:14 Comment(2)
this might help...#16778034Abutment
Ever solve this issue?Prostyle

© 2022 - 2024 — McMap. All rights reserved.