2

We are creating an app using KMM. But we are facing an issue, kSoap2 Library works fine in the android app but when this library used in Shared Directory of Android Studio, it doesn't work and gives error. The Same thing applies to Calendar. It is also not working, when writing Calendar.getInstance() the error says

Cannot access 'Kotlin.Cloneable'' which is a supertype of 'java.util.Calendar'. Check your module classpath for missing or conflicting dependencies

build.gradle.kts(for Shared)

    import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
    
     
    
    plugins {
    
        kotlin("multiplatform")
    
        id("com.android.library")
    
    }
    
    repositories {
    
        google()
    
        mavenCentral()
    
    }

 

kotlin {

    android()

 

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =

        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)

            ::iosArm64

        else

            ::iosX64

 

    iosTarget("ios") {

        binaries {

            framework {

                baseName = "shared"

            }

        }

    }

 

    sourceSets {

        val commonMain by getting {

            dependencies {

//                implementation("com.facebook.android:facebook-android-sdk:[5,6)")

//                implementation("com.google.android.material:material:1.3.0")

//                implementation("com.google.firebase:firebase-messaging:10.2.1")

//                implementation("com.google.android.gms:play-services:10.2.1")

//                implementation("com.google.android.gms:play-services-ads:10.2.1")

//                implementation("com.google.firebase:firebase-core:10.2.1")

//                implementation("com.google.firebase:firebase-auth:10.2.1")

//                implementation("com.github.siyamed:android-shape-imageview:0.9.+@AndreiA")

//                implementation("com.github.barteksc:android-pdf-viewer:3.1.0-beta.1")

//                implementation("org.apache.commons:commons-io:1.3.2")

 

 

                implementation("com.google.android.material:material:1.3.0")

                implementation("androidx.appcompat:appcompat:1.2.0")

                implementation("androidx.legacy:legacy-support-v13:1.0.0")

                implementation("androidx.core:core:1.0.0")

                implementation("androidx.legacy:legacy-support-v4:1.0.0")

                implementation("androidx.constraintlayout:constraintlayout:1.1.3")

                implementation("com.android.support.constraint:constraint-layout:")

                implementation("com.google.firebase:firebase-messaging:10.2.1")

                implementation("com.google.android.gms:play-services:10.2.1")

                implementation("com.google.android.gms:play-services-ads:10.2.1")

                implementation("com.google.firebase:firebase-core:10.2.1")

                implementation("com.google.firebase:firebase-auth:10.2.1")

                implementation("com.github.siyamed:android-shape-imageview:0.9.+@AndreiA")

                implementation("com.facebook.android:facebook-android-sdk:[5,6)")

                implementation("androidx.mediarouter:mediarouter:1.0.0")

                implementation("androidx.vectordrawable:vectordrawable:1.0.0")

                implementation("com.github.barteksc:android-pdf-viewer:3.1.0-beta.1")

                implementation("org.apache.commons:commons-io:1.3.2")

                implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.30")

            }

        }

 

        val commonTest by getting {

            dependencies {

                implementation(kotlin("test-common"))

                implementation(kotlin("test-annotations-common"))

            }

        }

        val androidMain by getting

        val androidTest by getting {

            dependencies {

 

                implementation(kotlin("test-junit"))

                implementation("junit:junit:4.13.2")

            }

        }

        val iosMain by getting

        val iosTest by getting

 

    }

}

 

apply { plugin("com.google.gms.google-services") }

 

android {

    compileSdkVersion(30)

    sourceSets["main"].manifest.srcFile("src//androidMain//AndroidManifest.xml")

 

    defaultConfig {

        minSdkVersion(17)

        targetSdkVersion(30)

    }

 

}

 

val packForXcode by tasks.creating(Sync::class) {

    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"

    val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)

    val targetDir = File(buildDir, "xcode-frameworks")

 

    group = "build"

    dependsOn(framework.linkTask)

    inputs.property("mode", mode)

 

    from({ framework.outputDirectory })

    into(targetDir)

}

 

tasks.getByName("build").dependsOn(packForXcode)

dependencies {

    implementation(files("/Users/mbp/AndroidStudioProjects/PashtoLibrary/androidApp/libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar"))

    implementation(files("/Users/mbp/AndroidStudioProjects/PashtoLibrary/androidApp/libs/org.apache.commons.net_2.0.0.v200905272248.jar"))

}

build.gradle.kts(for AndroidApp):

import org.jetbrains.kotlin.gradle.targets.js.npm.includedRange

 

plugins {

    id("com.android.application")

    kotlin("android")

 

}

repositories {

    google()

    jcenter()

}

dependencies {

    /*implementation(project(":shared"))

    implementation("com.google.android.material:material:1.3.0")

    implementation("androidx.appcompat:appcompat:1.2.0")

    implementation("androidx.constraintlayout:constraintlayout:2.0.4")*/

    implementation(project(":shared"))

 

    implementation("androidx.multidex:multidex:2.0.0")

 

    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

    implementation(files("libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar"))

    implementation(files("libs/pinchzoom.jar"))

    implementation(files("libs/org.apache.commons.net_2.0.0.v200905272248.jar"))

    implementation(files("libs/StartAppInApp-3.4.2.jar"))

    implementation(files("libs/picasso-2.5.2.jar"))

//    implementation("com.google.android.material:material:1.3.0")

//    implementation("androidx.appcompat:appcompat:1.2.0")

//

//    implementation("androidx.appcompat:appcompat:1.0.0")

//    implementation("androidx.legacy:legacy-support-v13:1.0.0")

//    implementation("androidx.core:core:1.0.0")

//    implementation("androidx.legacy:legacy-support-v4:1.0.0")

//

//

//    implementation("androidx.constraintlayout:constraintlayout:1.1.3")

//    implementation("com.android.support.constraint:constraint-layout:")

//    implementation("com.google.firebase:firebase-messaging:10.2.1")

//    implementation("com.google.android.gms:play-services:10.2.1")

//    implementation("com.google.android.gms:play-services-ads:10.2.1")

//    implementation("com.google.firebase:firebase-core:10.2.1")

//    implementation("com.google.firebase:firebase-auth:10.2.1")

//    implementation("com.github.siyamed:android-shape-imageview:0.9.+@AndreiA")

//    implementation("com.facebook.android:facebook-android-sdk:[5,6)")

//    implementation("androidx.mediarouter:mediarouter:1.0.0")

//    implementation("androidx.vectordrawable:vectordrawable:1.0.0")

//    implementation("com.github.barteksc:android-pdf-viewer:3.1.0-beta.1")

//    implementation("org.apache.commons:commons-io:1.3.2")

//

//

//    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.30")

 

}

apply { plugin("com.google.gms.google-services") }

 

android {

    compileSdkVersion(30)

    defaultConfig {

        applicationId = "co.beyondsolutions.libraryapp"

        minSdkVersion(17)

        targetSdkVersion(30)

        versionCode = 1

        versionName = "1.0"

 

        multiDexEnabled = true

    }

    buildTypes {

        getByName("release") {

            isMinifyEnabled = false

        }

    }

}
Róbert Nagy
  • 6,720
  • 26
  • 45
hamza
  • 53
  • 1
  • 6

1 Answers1

3

All your android dependencies should be moved to the androidMain sourceSet from commonMain.

As a general rule in common you can only have dependencies that can compile to all your targets. Since your android dependencies are under the common source set it doesn't really know how to compile those to iOS

Here's an example of using the Android Arch viewmodel: https://github.com/halcyonmobile/MultiplatformPlayground/blob/master/common/src/androidMain/kotlin/com/halcyonmobile/multiplatformplayground/shared/CoroutineViewModel.kt

Róbert Nagy
  • 6,720
  • 26
  • 45