suparngp / kotlin-multiplatform-projects

Kotlin Multiplatform projects.
https://kmpdocs.suparnatural.com
MIT License
128 stars 9 forks source link

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

Open MateuszKrawczuk opened 3 years ago

MateuszKrawczuk commented 3 years ago

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:

Additional context Add any other context about the problem here.

suparngp commented 3 years ago

@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")
        }
    }
}
MateuszKrawczuk commented 3 years ago

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

marclefrancois commented 3 years ago

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 :) )

suparngp commented 3 years ago

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.

marclefrancois commented 3 years ago

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

suparngp commented 3 years ago

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

suparngp commented 3 years ago

@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?