Tuesday, 21 June 2022

AGP: How to tell gradle to pick a specific dependency variant

Assume I have an app with two build types debug and release. And there is an artifact in the maven repository that was published using the gradle variants API. When you look into the .module file you can find

    {
      "name": "anotherBuildTypeVariantCustomApiPublication",
      "attributes": {
        "com.android.build.api.attributes.BuildTypeAttr": "anotherBuildType",
        "org.gradle.category": "library",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.libraryelements": "aar",
        "org.gradle.usage": "java-api"
      },
      "files": [
        {
          "name": "libraryname-0.1-anotherBuildType.aar",
          "url": "libraryname-0.1-anotherBuildType.aar",
          ....
        }
      ]
    }

How to tell gradle to pick anotherBuildType variant but not having to create a new variant of my app?

Currently gradle complains with

Variant 'anotherBuildTypeVariantCustomApiPublication' capability com.example:libraryname:0.1:
         - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'anotherBuildType' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'


from AGP: How to tell gradle to pick a specific dependency variant

No comments:

Post a Comment