Search code examples
androidkotlin-multiplatform

How to use KMM Reaktive Single inside native Android Project


I have this in my shared module

fun getAssignedBooks(): SingleWrapper<List<String>> {
        return singleFromCoroutine {
            callAssignedBooks()
        }
            .subscribeOn(ioScheduler)
            .observeOn(mainScheduler)
            .wrap()
    }

If I simply call this from my native Android app like so:

val assignedBooks = SharedBookRepository().getAssignedBooks()
assignedBooks.subscribe()

I get this compile time error on the .subscribe() method:

Cannot access 'com.badoo.reaktive.base.Source' which is a supertype of 'com.badoo.reaktive.single.SingleWrapper'. Check your module classpath for missing or conflicting dependencies
Cannot access 'com.badoo.reaktive.single.Single' which is a supertype of 'com.badoo.reaktive.single.SingleWrapper'. Check your module classpath for missing or conflicting dependencies

I saw there's a com.badoo.reaktive:rxjava2-interop:xxxx library, but not sure how I would apply it in this case.

I'd like to have both native Android and native Swift projects call this shared module method. The SingleWrapper I guess solves that for iOS?! (maybe ?! i don't know) but what about Android?

How can I achieve this? call getAssignedBooks from existing native projects ?


Solution

  • The error says that your Android app module doesn't have access to the Reaktive library. You can try one of the following.

    1. Define Reaktive dependency as api in your shared module:
    kotlin {
        sourceSets {
            commonMain {
                dependencies {
                    api("com.badoo.reaktive:reaktive:<version>")
                }
            }
        }
    }
    

    --- or ---

    1. Define the dependency as implementation in your Android app module:
    dependencies {
        implementation("com.badoo.reaktive:reaktive:<version>")
    }