0

I have my android Project with five Product flavour as:

 productFlavors {
    'Dev' {
        manifestPlaceholders = [appName: "Product"]
    }

    'Diamond' {
        manifestPlaceholders = [appName: "Product-Diamond"]
        applicationId GROUP.toString() + ".oc"
    }

    'Gold' {
        manifestPlaceholders = [appName: "Product-Gold"]
        applicationId GROUP.toString() + ".Gold"
    }

    'Silver' {
        manifestPlaceholders = [appName: "Product-Silver"]
        applicationId GROUP.toString() + ".Silver"
    }

    'Bronze' {
        manifestPlaceholders = [appName: "Product-bronze"]
        applicationId GROUP.toString() + ".bronze"
    }
 }

And I have one module name as premimum, which I'm including to my main project using:

dependencies {
 implementation project(path: ':premimum')
}

The problem I'm facing is, I just want to use this modulepremimum, inside Dev and Diamond flavour, I want to add the premimumdependency only for these two flavour, how can I do that.

My gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.binarybuff.appgo"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "default"
    productFlavors {
        Dev {
            manifestPlaceholders = [appName: "Product"]
        }

        Diamond {
            manifestPlaceholders = [appName: "Product-Diamond"]
            applicationId "com.binarybuff.appgo" + ".oc"
        }

        Gold {
            manifestPlaceholders = [appName: "Product-Gold"]
            applicationId "com.binarybuff.appgo" + ".Gold"
        }

        Silver {
            manifestPlaceholders = [appName: "Product-Silver"]
            applicationId "com.binarybuff.appgo" + ".Silver"
        }

        Bronze {
            manifestPlaceholders = [appName: "Product-bronze"]
            applicationId "com.binarybuff.appgo" + ".bronze"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//    implementation project(path: ':premium')
//    DiamondImplementation project(":premium")
    DiamondImplementation project(path: ':premium' )
}

I already look for this and found: Library Publication

Gradle: add dependency for a specific flavour of the library

I follow the above links but failed. please help.

HAXM
  • 3,578
  • 4
  • 31
  • 38

3 Answers3

0
dependencies {
 implementationPremium project(path: ':premimum')
}

You can do that by writing variantName + implementation. Your project may not be compiled if source directories are suitable up to your partial dependencies.

You can avoid it by writing

dependencies {
 provided project(path: ':premimum')
}

But make sure dont execute it for variants did not have that dependency otherwise you have ClassNotFoundException

Emre Aktürk
  • 3,306
  • 2
  • 18
  • 30
  • thanks, but this didn't help, I got error `Could not find method implementationDevDebug() for arguments [DefaultProjectDependency{dependencyProject='project ‘:premimum’’, configuration=‘DevDebug’}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.` – HAXM Oct 17 '18 at 12:25
0

To configure a dependency for a specific build variant, you could prefix the name of the build variant before the Implementation keyword, as below example:

dependencies {
    // Adds the local "mylibrary" module as a dependency to the "free" flavor.
    freeImplementation project(":mylibrary")
}

please modify your build.gradle file like above example.

Edited:

Dev {  //not 'Dev'
    manifestPlaceholders = [appName: "Product"]
}
navylover
  • 12,383
  • 5
  • 28
  • 41
0

Try giving the configuration as well. As you don't have flavours in your library module, setting configuration as 'default' should work for you. Here are the two lines of code you wanna add

DevImplementation project(path: ':premimum', configuration: 'default')
DiamondImplementation project(path: ':premimum', configuration: 'default')
Abhi
  • 2,115
  • 2
  • 18
  • 29