2

This issue should solve my other issue where I need to update the child libraries content provider: Using build types in Gradle libraries to run same app that uses ContentProvider on one device

I have a product flavor in the root application that is successfully changing the package name so I can deploy different versions of the app. When I try to add the same product flavor in a child library, the build fails because the root application fails to load a java class that is referenced from the child library because now the package name has changed? I thought that product flavors did not effect the java class package structure?

ATCApp.gradle root application

...
dependencies {
...
compile project(':libraries:FYC')
...
}

...
android
{
    ...
    productFlavors
    {
        prod {
           packageName "com.company.android"
        }

        qa {
           packageName "com.company.android.qa"
        }
    }
}

FYC.gradle child library

...
android
{
    ...
    productFlavors
    {
        prod {
           resValue "string", "authority", "com.company.android.fyc.models.listing.listingprovider"
        }

        qa {
           resValue "string", "authority", "com.company.android.qa.fyc.models.listing.listingprovider"
        }
    }
}

Adding the above product flavors in the child FYC library causes the root application to throw an error:

/src/main/java/com/company/android/HomeBroadcastReceiver.java:7: package com.company.android.fyc.controllers does not exist import com.company.android.fyc.controllers.FYCHomePagerActivity;

Thanks for any help!

Community
  • 1
  • 1
FinHead
  • 517
  • 4
  • 12

1 Answers1

1

I'm pretty sure you can't do dependencies on flavors (aka, chained flavors), as Gradle offers no way to express such a thing. Your root project can have different dependencies based on the flavor, but those dependencies cannot be explicit flavors themselves. The output of sub-projects should be predictable and consistent.

Community
  • 1
  • 1
Jeff Brateman
  • 3,229
  • 2
  • 20
  • 26
  • Wow, that's bad, because then I can't adjust the content provider based on the product flavor and I'll have to manually change the content provider whenever I need a new QA build. – FinHead Jul 14 '14 at 16:07
  • I'm sure you can extract the flavor-specific logic into your parent project, and pass it into your library project. – Jeff Brateman Jul 14 '14 at 18:33
  • It goes back to solving my original issue: http://stackoverflow.com/questions/24644274/using-build-types-in-gradle-libraries-to-run-same-app-that-uses-contentprovider. I have a contentprovider in the library project, but when I run the QA version of the app, I have to change the package name of the provider. – FinHead Jul 14 '14 at 20:54