Samuel
09/29/2024, 4:00 PMactual
/ expect
and have an `if`/`else` to handle the desktop, web &etc. targets?Blaž Vantur
09/29/2024, 4:54 PMimport com.liftric.kvault.KVault
interface SecurePersistentStorageProvider {
val kVault: KVault
}
iosMain:
import com.liftric.kvault.KVault
class SecurePersistentStorageProviderImpl : SecurePersistentStorageProvider {
override val kVault: KVault
get() = KVault()
}
androidMain:
import android.content.Context
import com.liftric.kvault.KVault
class SecurePersistentStorageProviderImpl(context: Context) : SecurePersistentStorageProvider {
private val vault = KVault(context, "sp.bvantur.tasky.kvault")
override val kVault: KVault
get() = vault
}
Additional wrapper for Koin in iosMain:
fun initKoinIos(
): KoinApplication = initKoin(module {
singleOf(::SecurePersistentStorageProviderImpl).bind<SecurePersistentStorageProvider>()
})
And then you just provide the implementation for your interface directly in your native target projects with DI, in my example with Koin:
Android native project:
initKoin(
targetModule = module {
single<Context> { this@TaskyApplication }
}
)
iOS native project:
KoinIOSKt.doInitKoinIos()
Just an alternative to expect-actual
mechanism without strict need to cover an actual
implementation in all targets.Blaž Vantur
09/29/2024, 5:11 PMif-else
statements, yes. Or maybe there is a way to write one default implementation for other targets that is being used for non-supported targets and iOS and Android would still use the implementation in the way I wrote in my message above. That way you could also eliminate a need for if-else
statements. Just an idea maybe worth exploring. ;)Samuel
10/01/2024, 2:22 PMiosArm64.deploymentTarget = "13.5"
Samuel
10/01/2024, 2:26 PMiosX64()
iosX64.deploymentTarget = "13.5"
iosX64().deploymentTarget = "13.5"
Inside or outside the kotlin { cocoapods
block, also tried in this block (also with/without cocoapods
):
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
iosTarget.deploymentTarget = "13.5"
}
Samuel
10/01/2024, 2:45 PMios.deploymentTarget = "13.5"
Samuel
10/01/2024, 4:37 PMerror: 'embedAndSign' task can't be used in a project with dependencies to pods.
and:
Failed to generate cinterop for :composeApp:cinteropBarcodeScanningIosX64:
Failed to generate cinterop for :composeApp:cinteropBarcodeScanningIosArm64
# repeat for other architectures
Giving these errors:
:composeApp:iosArm64Main: cinterop file: composeApp/build/classes/kotlin/iosArm64/main/cinterop/composeApp-cinterop-BarcodeScanning.klib does not exist
# repeat for other architectures
Yuvaraj
10/01/2024, 10:25 PMpod("GoogleMLKit/BarcodeScanning") {
moduleName = "MLKitBarcodeScanning"
version = locallibs.versions.ios.google.barcode.scanning.get()
}
Samuel
10/01/2024, 11:59 PMlocallibs
? - I had what you had but "3.2.0"
there instead and that's what gave the errors. - Happy to try your solution, what's the trick?
I also tried with a custom Podfile
Samuel
10/07/2024, 4:10 PMYuvaraj
10/07/2024, 9:57 PMYuvaraj
10/07/2024, 10:02 PMTakhir
10/19/2024, 3:46 PMSamuel
10/19/2024, 4:45 PM