kotlin-multiplatform-projects icon indicating copy to clipboard operation
kotlin-multiplatform-projects copied to clipboard

[BUG] Supernatural-fs 1.0.12 doesn't support different flavours of application

Open MateuszKrawczuk opened this issue 3 years ago • 7 comments

Describe the bug After upgrading to 1.0.12 library has an issue with handling different flavors of application. I have to prepare different builds for Development and Release, but it is not possible due to error when resolving dependencies. Downgrading to 1.0.10 solves the problem, but the project is migrating to Kotlin 1.4 and the newer version of the library build with the up-to-date release of Kotlin is highly recommended.

To Reproduce Steps to reproduce the behavior: Create an android app and library using Flavour dimensions in build.gradle.kts

    flavorDimensions("servconf")

    productFlavors {
        create("dev") {
            dimension("servconf")
        }
        create("production") {
            dimension("servconf")
        }
    }

Expected behavior Application builds without issue with solving dependencies.

Stacktrace Gradle output:

Could not determine the dependencies of task ':company-mobile-multiplatform:advertisingmonitor:compileDevDebugKotlin'.
> Could not resolve all files for configuration ':company-mobile-multiplatform:advertisingmonitor:devDebugRuntimeClasspath'.
   > Could not resolve suparnatural-kotlin-multiplatform:fs-android:1.0.12.
     Required by:
         project :company-mobile-multiplatform:advertisingmonitor > project :company-mobile-multiplatform:data
      > No matching variant of suparnatural-kotlin-multiplatform:fs-android:1.0.12 was found. The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'servconf' with value 'dev', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'android-releaseApiElements' capability suparnatural-kotlin-multiplatform:fs-android:1.0.12 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
              - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
              - Other compatible attribute:
                  - Doesn't say anything about servconf (required 'dev')
          - Variant 'android-releaseRuntimeElements' capability suparnatural-kotlin-multiplatform:fs-android:1.0.12 declares a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
              - Other compatible attribute:
                  - Doesn't say anything about servconf (required 'dev')
          - Variant 'metadata-api' capability suparnatural-kotlin-multiplatform:fs-android:1.0.12:
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about servconf (required 'dev')
          - Variant 'metadata-commonMainMetadataElements' capability suparnatural-kotlin-multiplatform:fs-android:1.0.12:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about servconf (required 'dev')
   > Could not resolve suparnatural-kotlin-multiplatform:fs-metadata:1.0.12.
     Required by:
         project :company-mobile-multiplatform:advertisingmonitor > project :company-mobile-multiplatform:data
      > No matching variant of suparnatural-kotlin-multiplatform:fs-metadata:1.0.12 was found. The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'servconf' with value 'dev', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'metadata-api' capability suparnatural-kotlin-multiplatform:fs-metadata:1.0.12:
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about servconf (required 'dev')
          - Variant 'metadata-commonMainMetadataElements' capability suparnatural-kotlin-multiplatform:fs-metadata:1.0.12:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about servconf (required 'dev')

Version 1.0.12

Platforms affected:

  • iOS [x]
  • Android [x]
  • JVM [ ]

Additional context Add any other context about the problem here.

MateuszKrawczuk avatar Oct 21 '20 10:10 MateuszKrawczuk

@MateuszKrawczuk thanks for reporting. Could it be solved by providing a fallback value like mentioned in the docs?

https://kotlinlang.org/docs/reference/mpp-publish-lib.html#publish-an-android-library


android {
    buildTypes {
        val staging by creating {
            // ...
            matchingFallbacks = listOf("release", "debug")
        }
    }
}

suparngp avatar Oct 22 '20 15:10 suparngp

It may fix the issue, but I didn't have time to rebuild this library and test this solution.

MateuszKrawczuk avatar Nov 02 '20 09:11 MateuszKrawczuk

Gave it a try (was having the same issue) and adding

buildTypes {
        ...
        debug {
            ...
            matchingFallbacks = ['release']
           ...
        }
    }

To all the modules of my android App seemed to fix the problem.

Any chance you could fix the library packaging ? (If it is the actual problem :) )

marclefrancois avatar Nov 02 '20 16:11 marclefrancois

I am not sure if this is something I should fix on the library level or if it is better for the consumers to have total control over the fallback. Any suggestions are welcome.

suparngp avatar Nov 03 '20 08:11 suparngp

Maybe but quick question (far for a KMP build expert): Shouldn't a debug build be packaged also ?

marclefrancois avatar Nov 03 '20 18:11 marclefrancois

Sounds good, I ll start publishing the debug builds from the next version onwards.

suparngp avatar Nov 04 '20 03:11 suparngp

@marclefrancois currently, I am publishing the android debug builds as well which you can add like following:

implementation 'suparnatural-kotlin-multiplatform:fs-android-debug:1.0.12' Is this enough to solve the use case?

suparngp avatar Nov 07 '20 05:11 suparngp