Export Dependencies To Kotlin
How It works
On completion with using external dependencies, it's possible to export them to Kotlin, if they are compatible.
Exported dependency can be used inside the bridge, the Swift & Kotlin App.
Note
If your package doesn't work with the plugin, please create an issue.
Bridge Incompatible Dependencies
In a case the exported dependency is written in Swift, manual work needs to be done like this.
For example, the CryptoSwift can't work directly on Kotlin, so the Plugin's bridge is here to fill the hole between Kotlin and Swift.
Gradle
The following configuration export to Kotlin the package FirebaseAnalytics which is a ObjC library.
Don't export incompatible library
Exporting an incompatible library is useless and will only increase build time.
swiftPackageConfig {
create("[cinteropName]") {
dependency {
remotePackageVersion(
url = URI("https://github.com/firebase/firebase-ios-sdk.git"),
products = {
add("FirebaseAnalytics", exportToKotlin = true), // exported
add("FirebaseCore") // non-exported
},
version = "11.8.0",
)
// Another SwiftDependency
// ...
)
}
}
Warning
A local swift package is being generated during the build and this message displayed
Spm4Kmp: A local Swift package has been generated at
/path/to/the/local/package
Please add it to your xcode project as a local package dependency.
Note : When updating your configuration, reset the package cache to apply the modification.
Example
import FirebaseAnalytics.FIRConsentStatusGranted
@ExperimentalForeignApi
val consentStatusGranted = FIRConsentStatusGranted
Note
The bridge can remain empty as we don't need it; we only want to use the exported product.