whyoleg/cryptography-kotlin

I have an error implementing cryptography-bom in the commonMain module

ArleyPereira opened this issue ยท 11 comments

Project: Compose Multiplatform
Library version: 0.3.0
agp = "8.2.0"
kotlin = "1.9.22"
compose-bom = "2024.02.02"

I have an error implementing cryptography-bom in the commonMain module
cryptography-bom
cryptography-core
provider-jdk

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':composeApp:iosArm64CompilationDependenciesMetadata'.

Screenshot at Mar 26 08-31-53

Hey!
BOM is JVM-only thing, so I would not expect it to work properly for commonMain. Or may be you have an example of working BOM in KMP projects?

I believe it could be easier to just use published Version Catalog: https://whyoleg.github.io/cryptography-kotlin/gradle-version-catalog/

Same error for me: Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':composeApp:iosArm64CompilationDependenciesMetadata'.

@ngallazzi may be you know any example of working BOM in KMP projects? So I could investigate support for BOM outside of JVM?

Hello, an example of using BOM in KMP projects is Koin.

koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin" }

https://insert-koin.io/docs/setup/koin

Okay, I've rechecked with the sample project from https://kmp.jetbrains.com and BOM is working fine with KMP. So cryptography-bom works as expected.
Though, the error comes from different place - looks like you are declaring dependency on cryptography-provider-jdk in common sourceSet. And because provider-jdk is supported only for jvm and android it doesn't work.
Gradle even shows something like this in an error message:

No matching variant of dev.whyoleg.cryptography:cryptography-provider-jdk:0.3.1 was found. The consumer was configured to find a library for use during 'kotlin-metadata', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64', attribute 'org.jetbrains.kotlin.platform.type' with value 'native' but:
...

Not very understandable error, yeah.

So, to solve the issue, you need to add dependencies on different providers for jvmMain/androidMain and iosMain sourceSets. Information about compatibility of different providers with targets can be found on website.

Also you can take a look on how tests-publication configures dependencies.

Still, looks like documentation is lacking some context. So I will create more self-describing samples for the following release, as well as add more documentation.

Thank you very much for the tips. I will carry out tests and report the results as soon as possible.

Anyone has a working example about dependency import for android/ios?

Anyone has a working example about dependency import for android/ios?

@Moozart Have you found a solution?

To add library to android/iOS project you need to add dependency on core artefact for commonMain and provider dependency for iosMain/androidMain sourceSets, f.e:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation(project.dependencies.platform("dev.whyoleg.cryptography:cryptography-bom:0.3.1"))
            implementation("dev.whyoleg.cryptography:cryptography-core")
        }
        androidMain.dependencies {
            implementation("dev.whyoleg.cryptography:cryptography-provider-jdk")
        }
        iosMain.dependencies {
            implementation("dev.whyoleg.cryptography:cryptography-provider-openssl3-prebuilt")
            // or `apple` provider
            // implementation("dev.whyoleg.cryptography:cryptography-provider-apple")
        }
    }
}

Does it solve your issue?
I will come-up with some of the examples on how to add library to projects, at least for mobile use-case, for upcoming release.

Hooray, the project started without errors and I was even able to reproduce the example on android

But I launched it without a bom dependency.
Thanks!

I think that the issue could be closed.
Additionally README was updated in #42 and now it better shows on how to correctly add dependencies