Skip to main content

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

app/build.gradle.kts
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:

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.

  1. If not already installed, set up CocoaPods.
  2. Open app/build.gradle and add ScanbotBarcodeScannerSDK in the cocoapods 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
}
  1. Sync your project to create the required podspec file.
./gradlew sync
  1. 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
  1. Save the Podfile and run the following command in your project directory:
pod install --repo-update
  1. Sync the project, and it will build successfully.
  2. Open the iosApp.xcworkspace via Xcode, set your signing, then build and run the app.
  3. You may get an error message as below.
'embedAndSign' task can't be used in a project with dependencies to pods.
  1. 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

  1. Copy the ScanbotBarcodeScannerSDK.xcframework folder into your app's iosApp project directory.

alt

  1. Open your app project in Xcode.

alt

  1. Then drag and drop the ScanbotBarcodeScannerSDK.xcframework into the Frameworks, Libraries and Embeded Content section.

alt

  1. 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
  1. Open app/build.gradle and add ScanbotBarcodeScannerSDK.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)
}
}

//...
}
  1. 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

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?