Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flavorDimensions gradle error - Android Studio 3.0 Canary 1

I would like to upgrade my project to Android Studio 3.0 Canary 1 and the gradle:3.0.0-alpha1 plugin, however I have a problem with the correct definition of flavors for included projects.

I followed the official migration guide from Google: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html

In my main app build.gradle I defined the "myflavor" flavorDimensions, as recommended by the migration guide:

android {
    flavorDimensions "myflavor"

    productFlavors {
        dev {
            dimension "myflavor"
            minSdkVersion 21
        }
        prod {
            dimension "myflavor"
            minSdkVersion 16
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }

        release {
            debuggable false

            signingConfig signingConfigs.release

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
}

dependencies {
    compile project(':util')
}

In my included :util module (producer), I tried to include it withouth a definition of flavorDimensions, productFlavors and buildTypes. I get the following gradle error:

Error:Could not resolve all dependencies for configuration ':app:prodDebugCompileClasspath'.
  Cannot choose between the following configurations on project :util:
    - debugApiElements
    - releaseApiElements
  All of them match the consumer attributes:
    - Configuration 'debugApiElements':
        - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided.
        - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required.
        - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided.
        - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but wasn't required.
        - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
        - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided.
        - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'.
    - Configuration 'releaseApiElements':
        - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided.
        - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required.
        - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided.
        - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=release}' but wasn't required.
        - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
        - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided.
        - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'.

When defining the same flavorDimensions, productFlavors and buildTypes in :util as in the main :app, I get the following error message:

Error:Could not resolve all dependencies for configuration ':app:prodDebugCompileClasspath'.
Cannot choose between the following configurations on project :util:
  - devDebugApiElements
  - devReleaseApiElements
  - prodDebugApiElements
  - prodReleaseApiElements
All of them match the consumer attributes:
  - Configuration 'devDebugApiElements':
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=devDebug}' but wasn't required.
      - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided.
      - Found myflavor 'ProductFlavorAttr{name=dev}' but wasn't required.
      - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'.
  - Configuration 'devReleaseApiElements':
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=release}' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=devRelease}' but wasn't required.
      - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided.
      - Found myflavor 'ProductFlavorAttr{name=dev}' but wasn't required.
      - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'.
  - Configuration 'prodDebugApiElements':
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=prodDebug}' but wasn't required.
      - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided.
      - Found myflavor 'ProductFlavorAttr{name=prod}' but wasn't required.
      - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'.
  - Configuration 'prodReleaseApiElements':
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided.
      - Found com.android.build.gradle.internal.dependency. 'BuildTypeAttr{name=release}' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=prodRelease}' but wasn't required.
      - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided.
      - Found myflavor 'ProductFlavorAttr{name=prod}' but wasn't required.
      - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'.

What is the correct way to include my :util lib without getting the error?

like image 627
Devdroid Avatar asked May 22 '17 13:05

Devdroid


People also ask

How to add new build variant in Android Studio?

You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. To start customizing each build variant with its own features and resources, however, you'll need to know how to create and manage source sets.

What is buildtype in Gradle?

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.

What is missingDimensionStrategy?

void missingDimensionStrategy ( String dimension, String requestedValue) Specifies a flavor that the plugin should try to use from a given dimension in a dependency. Android plugin 3.0. 0 and higher try to match each variant of your module with the same one from its dependencies.

What is Flavour dimension?

Flavor Dimensions is a way to group flavors by a name. For now, we're using just a single group. Add the following line in your defaultConfig block: flavorDimensions "default" Now syncing the gradle would give you the following product flavors: Android Build Variants combine build types and product flavors.


2 Answers

Seems like a bug in the Gradle build process, I'm not quite sure why exactly it's not working. I was stuck on this for a while but I was able to fix it by changing

compile project(':util')

to

compile project(path: ':util', configuration: 'default')

Let me know if this works for you!

like image 83
Moez Avatar answered Nov 14 '22 01:11

Moez


I had a similar issue using Canary 2, but the proposed solution didn't work. Apparently there is a way to use the implementation from a Local library or project:

// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')

// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')

Reference from Studio Documentation.

like image 9
amouly Avatar answered Nov 14 '22 00:11

amouly