0

I have a project with multiple library modules in it. I want to create unique flavors in one the modules, but I've encountered a strange error that I'm having trouble solving.

In my module's gradle file I have the following:

android {
    defaultConfig {
        testApplicationId "com.mytestApplication"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    productFlavors {
       flav1 {
            buildConfigField 'String', 'PROJECT', '"Flav1"'
        }
        flav2{
            buildConfigField 'String', 'PROJECT', '"Flav2"'
        }
    }
}

But I keep getting the error:

Error:Cannot add task ':myaccessorModule:jarRelease' as a task with that name already exists. 

if my build.gradle file is written like this:

android {
    defaultConfig {
        testApplicationId "com.mytestApplication"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    productFlavors {
       flav1 {
            buildConfigField 'String', 'PROJECT', '"Flav1"'
        }
    }
}

Then it will actually show me the flav1Debug and flav1Release options in the Build Variant window.

I'm wondering why it fails when trying to use two or more flavors? I have not defined any flavors in any of my other modules. All documentation I've seen makes this look pretty easy. I've also tried adding these flavors to my module through the project structure GUI, but i'm getting the same results. How do I get this module to have multiple flavors?

Cheers.

Dave
  • 3,178
  • 5
  • 28
  • 44

1 Answers1

0

Usually product flavors are used to create multiple apk versions with the same code.

So it should have unique applicationIds for each flavor.

Try using

productFlavors {
       flav1 {
            applicationId "com.mytestApplication.flav1"
        }
        flav2{
            applicationId "com.mytestApplication.flav2"
        }
    }

For more info, https://developer.android.com/studio/build/build-variants.html

  • Thanks for the response Jaswanth. I've actually tried that before just to see if it would work, but unfortunately it didn't. I've just found out though that different flavors are only available for applications and not libraries. (use apply plugin: 'com.android.application' instead of apply plugin: 'com.android.library'" So unfortunately it's looking like library projects can only be a single flavor at this point. :( – Dave Sep 02 '16 at 22:12
  • Just remembered something. Can you have a look at this answer ? http://stackoverflow.com/a/24316133/1852441. – Jaswanth Manigundan Sep 04 '16 at 23:28
  • It is similar to adding flavored dependencies to wear module (if you have experience with wear apps) – Jaswanth Manigundan Sep 04 '16 at 23:29