7

I have defined a few flavors and buildTypes for my android app

productFlavors {
    X {
        applicationId = "com.x.xxxx"
    }
    Y {
        applicationId = "com.y.yyyy"
    }
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard_rules.txt'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    }

    debug {
        applicationIdSuffix ".debug"
    }
}

That does the job of creating different flavors/buildType combinations.

Now to make sure that ContentProviders works and I do not get a Failure [INSTALL_FAILED_CONFLICTING_PROVIDER] error, I have changed the android:authorities="${applicationId}" and AUTHORITY references in code to BuildConfig.APPLICATION_ID.

That makes the ContentProvider work fine i.e it does not throw an error when I install two different types on the same phone. It lets me install them.

Next step is where the error is. I use SyncAdapter and AccountManager to control a few things. I have modified the ACCOUNT_TYPE to use the APPLICATION_ID. Because of the issue with gradle not being able to use ${applicationId} in non-manifest xml resource files, I have created a different directory structure for each flavor and copied the syncadapter.xml and authenticator.xml with corresponding authority and account type strings.

I have also tried the technique described in this blog - http://blog.jensdriller.com/android-gradle-workaround-for-missing-placeholder-support-in-resource-files/

And the top voted answers on Using build types in Gradle to run same app that uses ContentProvider on one device but things don't seem to work.

Anyone been able to get this to work recently?

Community
  • 1
  • 1
Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65

0 Answers0