Use External Dependencies
How It works
On completion with the basic configuration, it's possible to use external dependency with your bridge.
The plug-in uses the Swift Packages features to gather all dependency inside the bridge.
Note
If your package doesn't work with the plugin, please create an issue.
Use Dependencies In Your Application
By default, the dependencies are not available from your application, but if you need them, you can add them inside the includeProduct configuration.
Local Package
The included and some specific dependencies require to be declared on the Xcode side; in that case, you will see the following message during the build:
Spm4Kmp: The following dependencies [some_dependency_name] need to be added to your xcode project
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; it will add the missing content.
****You can ignore this messaging if you have already added these dependencies to your Xcode project****
If you encounter a crash or Undefined symbol error
during the build after adding this package,
please fill an issue!
Supported Dependency Sources
The plugin supports the following configurations :
XCFramework
The XCFrameworks are used for Local/Remote Binary and protecting source code distribution, learn more.
An example is available.
Gradle
The following configuration imports the package CryptoSwift which is a pure Swift library, that can't be used directly in Kotlin.
swiftPackageConfig {
create("[cinteropName]") {
dependency {
remotePackageVersion(
url = URI("https://github.com/krzyzanowskim/CryptoSwift.git"),
products = {
add("CryptoSwift")
},
version = "1.8.4",
)
// Another SwiftDependency
// ...
}
}
}
Example
Make your Swift code compatible with Kotlin.
Your Swift code needs to be marked as @objc/@objcMembers and the visibility set as public
or it won't be exported and available from your Kotlin code.