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

Cannot access class 'dev.gitlive.firebase.storage.Data' in androidApp #638

Open
mr-kew opened this issue Sep 27, 2024 · 4 comments
Open

Comments

@mr-kew
Copy link
Contributor

mr-kew commented Sep 27, 2024

I have a function in commonMain:

import dev.gitlive.firebase.storage.Data
...
fun getData(): Data {
    ...
}

and I am trying to call it from a androidApp (from compose):

Button(
    onClick = {
        val data = getData()
        ...
    }
)

but this gives me an error: Cannot access class 'dev.gitlive.firebase.storage.Data'. Check your module classpath for missing or conflicting dependencies..

I am doing just this in my :shared:build.gradle.kts:

commonMain.dependencies {
    implementation("dev.gitlive:firebase-storage:2.1.0")
}

I tried in commonMain:

public typealias StorageData = Data

but that basically tells me that type StorageData and dev.gitlive.firebase.storage.Data are not the same in androidApp.

Am I doing something wrong? Or is it an issue with the library?

@mr-kew
Copy link
Contributor Author

mr-kew commented Oct 3, 2024

@SebastianFelon But there already is an actual class for Data (and File) in androidMain in storage.kt.

Anyway I solved it for now by doing expect/actual StorageData that is identical to dev.gitlive.firebase.storage.Data in my code and converting to it. But it feels like an issue with the library.

@DjuroRad
Copy link

@mr-kew Could you please share your solution's implementation? I am having a similar issue. Trying to use storage and putByteArray which should be readily implemented with this library. Facing difficulties implementing a mapper from Kotlin's ByteArray to objective C's Data

@mr-kew
Copy link
Contributor Author

mr-kew commented Nov 25, 2024

@DjuroRad I never convert between ByteArray and NSData, I just use the platform dataWithMaxSize to get the NSData directly.

actual suspend fun StorageReference.getData(maxBytes: Long): Data = suspendCancellableCoroutine { continuation ->
    val task = this.ios.dataWithMaxSize(maxBytes) { data, error ->
        when {
            data != null -> continuation.resume(Data(data))
            error != null -> continuation.resumeWithException(FirebaseStorageException(error.localizedDescription))
            else -> continuation.resumeWithException(IllegalStateException())
        }
    }
    continuation.invokeOnCancellation {
        task.cancel()
    }
}

@DjuroRad
Copy link

Oh I see. I got it wrong in the first place, I was trying to use .putByteArray function in order to store it. I will just go with its Data class for this

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

No branches or pull requests

2 participants