Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage within multiplatform project fails: duplicate library name #671

Closed
Akazm opened this issue Jun 20, 2022 · 3 comments · Fixed by #672
Closed

Usage within multiplatform project fails: duplicate library name #671

Akazm opened this issue Jun 20, 2022 · 3 comments · Fixed by #672

Comments

@Akazm
Copy link

Akazm commented Jun 20, 2022

I've been working on adding reaktive to a Kotlin multiplatform project. I've therefore followed the provided documentation file within the project's doc folder, which unfortunately did not work. I've therefore tried to apply suggestions provided my IntelliJ, leading to another issue complaining about a duplicate library name (duplicate library name: com.badoo.reaktive:reaktive ).

This seems to make sense at first glance since I'm using platform-specific implementations for iOS (while deliberately ignoring Android for now). But whenever I erase the dependencies providing platform-specific implementations for iOS, reaktive cannot be exported using the export statement, since reaktive is not part of the platform-specific dependencies.

Here's my build.gradle.kts:

import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
    kotlin("multiplatform") version "1.6.20"
    id("com.android.library")
}

group = "de.itesign"
version = "1.0-SNAPSHOT"

repositories {
    google()
    mavenCentral()
}

val reaktiveVersion = "1.2.2"
val reaktiveIos64Version = "1.2.0"

kotlin {

    android()

    val xcf = XCFramework("SomeCommon")
    iosArm64 {
        binaries {
            framework {
                baseName = "SomeCommon"
                xcf.add(this)
                export("com.badoo.reaktive:reaktive-ios64:$reaktiveIos64Version")
            }
        }
    }
    iosSimulatorArm64() {
        binaries {
            framework {
                baseName = "SomeCommon"
                xcf.add(this)
                export("com.badoo.reaktive:reaktive-iossimulatorarm64:$reaktiveVersion")
            }
        }
    }
    iosX64 {
        binaries {
            framework {
                baseName = "SomeCommon"
                xcf.add(this)
                export("com.badoo.reaktive:reaktive-iossim:$reaktiveIos64Version")
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                api("com.badoo.reaktive:reaktive:$reaktiveVersion")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation("junit:junit:4.13")
            }
        }
        val iosArm64Main by getting {
            dependencies {
                api("com.badoo.reaktive:reaktive-ios64:$reaktiveIos64Version")
            }
        }
        val iosX64Main by getting {
            dependencies {
                api("com.badoo.reaktive:reaktive-iossim:$reaktiveIos64Version")
            }
        }
        val iosSimulatorArm64Main by getting {
            dependencies {
                api("com.badoo.reaktive:reaktive-iossimulatorarm64:$reaktiveVersion")
            }
        }
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosArm64Test by getting
        val iosX64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

Can you guys provide any help on what I'm doing wrong here? Is the documentation outdated?

@arkivanov
Copy link
Contributor

You definitely don't need to define platform specific dependencies like com.badoo.reaktive:reaktive-iossimulatorarm64:$reaktiveVersion. All you need to do is to specify the dependency in the commonMain source set, and also export it to the framework.

The following should work:

kotlin {

    android()

    iosArm64 {
        binaries {
            framework {
                baseName = "SomeCommon"
                export("com.badoo.reaktive:reaktive:$reaktiveVersion")
            }
        }
    }
    iosSimulatorArm64 {
        binaries {
            framework {
                baseName = "SomeCommon"
                export("com.badoo.reaktive:reaktive:$reaktiveVersion")
            }
        }
    }
    iosX64 {
        binaries {
            framework {
                baseName = "SomeCommon"
                export("com.badoo.reaktive:reaktive:$reaktiveVersion")
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                api("com.badoo.reaktive:reaktive:$reaktiveVersion")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation("junit:junit:4.13")
            }
        }

        val iosMain by creating { dependsOn(commonMain) }
        val iosArm64Main by getting { dependsOn(iosMain) }
        val iosX64Main by getting { dependsOn(iosMain) }
        val iosSimulatorArm64Main by getting { dependsOn(iosMain) }

        val iosTest by creating { dependsOn(commonTest) }
        val iosArm64Test by getting { dependsOn(iosTest) }
        val iosX64Test by getting { dependsOn(iosTest) }
        val iosSimulatorArm64Test by getting { dependsOn(iosTest) }
    }
}

@Akazm
Copy link
Author

Akazm commented Jun 20, 2022

Ah, I see, thanks for responding so quickly!

The description in the documentation is different from what you're describing here, though.

@arkivanov
Copy link
Contributor

Let's keep this issue open until I update the Readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants