https://kotlinlang.org logo
#moko
Title
# moko
c

Christian Sousa

04/02/2020, 3:50 PM
Hello guys, can anyone give me some help regarding the
moko-resources
? I’m trying to build my project but it always gives me the following:
Object 'MR' has several compatible actual declarations in modules...
a

alex009

04/02/2020, 6:32 PM
hi! this error showed for android compilation or ios? and how you configure multiplatform targets?
c

Christian Sousa

04/03/2020, 8:56 AM
Hello! It showed for the ios (both the iosx64 and the arm variant). My config is the following:
Copy code
kotlin {

    iosX64()   // for iOS Simulator
    iosArm64() // for iOS arm64 devices

    sourceSets {
        iosMain {
            dependencies {
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-properties-native:$serialization_version"
                implementation "io.ktor:ktor-client-ios:$ktor_version"
                implementation "io.ktor:ktor-client-core-native:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
            }
        }

        configure([targets.iosX64, targets.iosArm64]) {
            compilations.main {
                source(sourceSets.iosMain)
            }
        }
    }

    cocoapods {
        summary = "My Lib"
        homepage = "<https://google.com>"
        frameworkName = "My Lib"

    }
}
Thank you for your time @alex009
a

alex009

04/03/2020, 9:29 AM
hm, i will try reproduce it later today. or you can give me github repo where it can be reproduced?
c

Christian Sousa

04/03/2020, 9:30 AM
It’s not public atm, but my gradle structure is the following
👌 1
root build.gradle
Copy code
apply from: rootProject.file("gradle/experimental.gradle")

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "<https://kotlin.bintray.com/kotlinx>" }
        maven { url '<https://dl.bintray.com/jetbrains/kotlin-native-dependencies>' }
        maven { url = "<https://dl.bintray.com/icerockdev/plugins>" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
        classpath "dev.icerock.moko:resources-generator:0.9.0"
        classpath "dev.icerock:mobile-multiplatform:0.6.1"
    }
}

allprojects {

    repositories {
        google()
        jcenter()
        maven { url "<https://kotlin.bintray.com/kotlinx>" }
        maven { url "<https://dl.bintray.com/kotlin/ktor>" }
        maven { url "<https://dl.bintray.com/icerockdev/moko>" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
the experimental.gradle
Copy code
ext.experimentalAnnotations = [
    "kotlin.Experimental",
    "kotlin.experimental.ExperimentalTypeInference",
    "kotlin.ExperimentalMultiplatform",
    "kotlinx.coroutines.ExperimentalCoroutinesApi",
    "kotlinx.coroutines.ObsoleteCoroutinesApi",
    "kotlinx.coroutines.InternalCoroutinesApi",
    "kotlinx.coroutines.FlowPreview"
]
My framework build.gradle
Copy code
plugins {
    id "com.android.library"
    id "dev.icerock.mobile.multiplatform-resources"
    id 'kotlin-multiplatform'
    id 'kotlin-native-cocoapods'
    id 'kotlinx-serialization'
}



version = "1.0"

apply from: project.file("gradle/target_android.gradle")
apply from: project.file("gradle/target_ios.gradle")



kotlin {
    sourceSets {
        all {
            languageSettings {
                progressiveMode = true
                experimentalAnnotations.each { useExperimentalAnnotation(it) } // kotlin.ExperimentalUnsignedTypes - annotation FQ-name
            }
        }
        commonMain {
            dependencies {
                implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-properties-common:$serialization_version"
                implementation "io.ktor:ktor-client:$ktor_version"
                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "io.ktor:ktor-client-json:$ktor_version"
                implementation "io.ktor:ktor-client-serialization:$ktor_version"
                implementation "com.benasher44:uuid:0.1.0"
                implementation "com.soywiz.korlibs.klock:klock:1.9.1"
                implementation "com.soywiz.korlibs.krypto:krypto:1.11.0"
                implementation "dev.icerock.moko:resources:0.9.0"
                implementation "com.google.android:flexbox:2.0.1"
            }
        }
    }
}


multiplatformResources {
    multiplatformResourcesPackage = "com.christiansousa.lib"
}
My target_android.gradle
Copy code
android {
    compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '<http://proguard-rules.pro|proguard-rules.pro>'
        }
    }
}

kotlin {
    android {
        publishAllLibraryVariants()
    }

    sourceSets {
        androidMain {
            kotlin.srcDir("src/androidMain/kotlin")
            dependencies {
                implementation kotlin('stdlib-jdk8')
                implementation "androidx.preference:preference-ktx:1.1.0"
                implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-properties:$serialization_version"
                implementation "io.ktor:ktor-client-android:$ktor_version"
                implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
                implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
                implementation "com.google.android.gms:play-services-tagmanager-v4-impl:17.0.0"
            }
        }
    }
}
My ios_target.gradle
Copy code
kotlin {
    iosX64()   // for iOS Simulator
    iosArm64() // for iOS arm64 devices

    sourceSets {
        iosMain {
            dependencies {
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-properties-native:$serialization_version"
                implementation "io.ktor:ktor-client-ios:$ktor_version"
                implementation "io.ktor:ktor-client-core-native:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
            }
        }

        configure([targets.iosX64, targets.iosArm64]) {
            compilations.main {
                source(sourceSets.iosMain)
            }
        }
    }

    cocoapods {
        // Configure fields required by CocoaPods.
        summary = "My Lib"
        homepage = "<https://google.com>"

        frameworkName = "MyLib"
    }
}
I think that everything relevant is in there
@alex009 let me know if you need something else
👌 1
a

alex009

04/03/2020, 3:53 PM
I reproduce bug. Later will publish bugfix release
Today or tomorrow
c

Christian Sousa

04/03/2020, 3:55 PM
Cool! Glad I could help 🙂
@alex009 one more thing. When generating the framework via the
cocoapods
it seems that my resources are not in there, therefore I can’t access images and so on. Is this somewhat related? Or do I need to do something extra?
a

alex009

04/04/2020, 5:56 AM
resoures on ios can be used only with dynamic frameworks. kotlin-native default cocoapods support produce static framework
i think it's reason in your case
i release version 0.9.1 with bugfixed duplication with hierarhical source sets
c

Christian Sousa

04/06/2020, 3:57 PM
@alex009 I was testing with my exact settings I provided before but I’m getting the same problem with the version 0.9.1
a

alex009

04/06/2020, 4:28 PM
Are you update gradle plugin version too?
c

Christian Sousa

04/07/2020, 11:36 AM
@alex009 I did, and with the previous setup everything was fine, but if I name the targets, the problem happens again:
Copy code
iosX64("ios") {
        binaries.framework {
            baseName = "MyLib"
        }
    }
    iosArm64("iosArm64") {
        binaries.framework {
            baseName = "MyLib"
        }
    }
Ok, got it working right now after some keyboard bashing. Anyway, I ran into another issue but I think that you somehow already answered before. I’m creating a FatFramework with the iosX64 and iosArm64 targets, and that doesn’t include the assets, however the iosX64 and iosArm64 alone have it. Is there any way around it?
a

alex009

04/08/2020, 1:22 PM
Hm, i not try fat frameworks with resources...how exactly you create fat?
7 Views