Installation
The Scanbot SDK is distributed through our private Maven repository server (nexus.scanbot.io
),
which needs to be specified in the settings.gradle.kts
file in the root folder of your project:
// settings.gradle.kts in the root of the project:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
// Add Scanbot SDK maven repositories here:
maven(url = "https://nexus.scanbot.io/nexus/content/repositories/releases/")
maven(url = "https://nexus.scanbot.io/nexus/content/repositories/snapshots/")
}
}
Afterward, the dependencies can be added in the dependencies
section of your Android application project configuration,
usually in the app/build.gradle.kts
file.
Requirements
Ensure the Kotlin version is set to 2.1.0-Beta2 or higher. Typically, this is defined in the libs.versions.toml
variable:
kotlin = "2.1.0-Beta2"
Main SDK dependency
commonMain.dependencies {
implementation("io.scanbot:scanbot-sdk-compose-multiplatform:$scanbotSdkVersion")
}
Get the latest $scanbotSdkVersion
from the Changelog.
Android
No additional configuration is needed.
iOS
The Scanbot Barcode Scanner SDK is available as an XCFramework and via CocoaPods:
- Direct download as XCFramework: ScanbotBarcodeScannerSDK.xcframework
- CocoaPods (XCFramework):
ScanbotBarcodeScannerSDK
Installation
Installation using CocoaPods
CocoaPods is a dependency manager for Swift and Objective-C projects for macOS as well as for iOS. It integrates deeply into your Xcode project and manages the third-party components in your application.
- If not already installed, set up CocoaPods.
-
- New Project: For new projects, follow the steps to configure a new project.
- Existing Project: If you already have a project, manually add and configure the Kotlin CocoaPods Gradle plugin.
- Open
app/build.gradle
and addScanbotBarcodeScannerSDK
in thecocoapods
section:
cocoapods {
// Required fields
version = "1.0"
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
// Match target in Podfile
ios.deploymentTarget = "16"
// Specify path to Podfile
podfile = project.file("../iosApp/Podfile")
framework {
baseName = "ComposeApp"
isStatic = true
}
pod("ScanbotBarcodeScannerSDK") {
version = "~> 6.0.1-Beta2"
packageName = "ScanbotBarcodeScannerSDK"
extraOpts += listOf("-compiler-option", "-fmodules")
}
xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = NativeBuildType.DEBUG
xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = NativeBuildType.RELEASE
}
- Sync your project to create the required
podspec
file.
./gradlew sync
- Open your
Podfile
in Xcode or a text editor, and add the following lines:
platform :ios, '16.0'
target 'iosApp' do
use_frameworks!
# Local podspec from path
pod 'composeApp', :path => '../composeApp/composeApp.podspec'
end
- Save the
Podfile
and run the following command in your project directory:
pod install --repo-update
- Sync the project, and it will build successfully.
- Open the
iosApp.xcworkspace
via Xcode, set your signing, then build and run the app. - You may get an error message as below.
'embedAndSign' task can't be used in a project with dependencies to pods.
- To solve this issue you have to add the below line of code to
gradle.properties
.
kotlin.apple.deprecated.allowUsingEmbedAndSignWithCocoaPodsDependencies=true
Now, sync and run the iOS app. It will build and run successfully.
Installation using XCFramework
- Copy the
ScanbotBarcodeScannerSDK.xcframework
folder into your app'siosApp
project directory.
- Open your app project in Xcode.
- Then drag and drop the
ScanbotBarcodeScannerSDK.xcframework
into theFrameworks, Libraries and Embeded Content
section.
- In your app's project folder, create a new file named
iosApp/ScanbotBarcodeScannerSDK.def
. Add the following content:
language = Objective-C
modules = ScanbotBarcodeScannerSDK
package = ScanbotBarcodeScannerSDK
- Open
app/build.gradle
and addScanbotBarcodeScannerSDK.xcframework
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
//...
kotlin {
// Initialize an instance of XCFramework to bundle and manage iOS frameworks
val xcf = XCFramework()
// Define the absolute paths to the ScanbotBarcodeScannerSDK framework files for both arm64 (device) and simulator architectures
val frameworkPath = project.file("$rootDir/iosApp/ScanbotBarcodeScannerSDK.xcframework").absolutePath
val frameworkPathArm64 = "$frameworkPath/ios-arm64/"
val frameworkPathSimulator = "$frameworkPath/ios-arm64_x86_64-simulator/"
// Function to configure Scanbot interop for a specified Kotlin Native target
fun configureScanbotInterop(target: org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget, frameworkPath: String) {
target.compilations.getByName("main") {
val coreScanbot by cinterops.creating {
defFile("$rootDir/iosApp/ScanbotBarcodeScannerSDK.def")
compilerOpts("-framework", "ScanbotBarcodeScannerSDK", "-F$frameworkPath")
extraOpts += listOf("-compiler-option", "-fmodules")
}
}
target.binaries.all {
linkerOpts("-framework", "ScanbotBarcodeScannerSDK", "-F$frameworkPath")
}
}
listOf(
iosArm64(),
iosSimulatorArm64(),
iosX64()
).forEach { target ->
val currentFrameworkPath = if (target.name.contains("arm64")) frameworkPathArm64 else frameworkPathSimulator
configureScanbotInterop(target, currentFrameworkPath)
target.binaries.framework {
baseName = "ComposeApp"
isStatic = true
xcf.add(this)
}
}
//...
}
- Run the following command to sync your project:
./gradlew sync
You should now be able to use the Scanbot Barcode Scanner SDK in your project.
Example Apps
- With CocoaPods Usage: Scanbot Barcode Scanner Example - CocoaPods
- With XCFramework Usage: Scanbot Barcode Scanner Example - XCFramework
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get free trial license