Hi There I am having a problem in Android Studio. ...
# gradle
p
Hi There I am having a problem in Android Studio. When creating a new variant in a
library
module the
app
module is not able to see that specific variant of the
library
.
Copy code
library build.gradle:

buildTypes {
    release {
        isMinifyEnabled = true
        isTestCoverageEnabled = true
        proguardFiles(
            getDefaultProguardFile("proguard-android-optimize.txt"),
            "<http://proguard-rules.pro|proguard-rules.pro>"
        )
    }

    debug {
        isJniDebuggable = true
        isTestCoverageEnabled = true
    }

    create("customVariant") {
        isJniDebuggable = true
        isTestCoverageEnabled = true
        matchingFallbacks += listOf("debug", "release")
    }
}
Copy code
sample module build.gradle:

dependencies {

    implementation("androidx.appcompat:appcompat:1.4.0")
    implementation ("com.google.android.material:material:1.4.0")

    //Lingo SDK
    implementation(project(":library", "customVariant"))
}
When trying to compile I get:
Copy code
Could not determine the dependencies of task ':sample:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':sample:debugCompileClasspath'.
   > Could not resolve project :library.
     Required by:
         project :sample
      > Project :sample declares a dependency from configuration 'implementation' to configuration 'customVariant' which is not declared in the descriptor for project :library
Has anyone experienced something similar? Thanks in advance
e
the configuration name in
project(..., configuration)
is not the name of the variant, you shouldn't override it that way anyways because there are multiple configurations for the code, android resources, etc.
p
So what would be the right thing to do in order for the sample module to see this particular variant of the library?
Should I create a task that gets the compileClasspath from the library project and set it as the configuration?
e
no. normally you would just use matching fallbacks to set the right variant, but it's hard to tell what your intended behavior here is - is customVariant built for debug or for release?
https://developer.android.com/studio/build/build-variants should describe everything you need. and for future reference, this isn't really a Kotlin-related issue, and would be better asked in an Android-specific community
p
I check that documentation already but it does not says much about what I want to achieve. I added
Copy code
matchingFallbacks += listOf("customVariant", "debug", "release")
to the sample project but still the same problem. My variant is intended for release but is not necessarily the release variant.
Or if I understand you correctly there are only 2 build types
debug
and
release
and my variant has to be part of one of them?
e
you misunderstand matchingFallbacks. what you have done is say that, when building library's customVariant, it can use either debug or release variants of its dependencies. that has nothing to do with other consumers, such as app, that want to use library
p
I see, ok. I tried with flavors instead of variants and apparently it works. I needed to define the same flavors in each project. Once I switch the same flavors in the Build Variants tab it seems to work. I am having now another issue related to kapt the kotlin annotation processor plugin. It has difficulty to process annotations in my flavor code.
Declaring the same variant name in the app module solve my problem, thanks for responding any ways