Scanbot SDK has been acquired by Apryse! Learn more

Learn more
Skip to content

How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Chandu November 19, 2024 4 mins read
Compose Multiplatform Barcode Scanner SDK

With our new Compose Multiplatform Barcode Scanner SDK, creating a cross-platform barcode scanning application for Android and iOS with a shared Kotlin codebase is straightforward. However, using CocoaPods can be tricky, since Compose primarily uses Kotlin Multiplatform and Gradle for dependency management. In this tutorial, we’ll show you how you can avoid common pitfalls and successfully build and run your Compose Multiplatform barcode scanning app.

If you haven’t worked with Kotlin Multiplatform before, set up your development environment according to the Kotlin documentation. After that, you’re ready to create your project.

Prepare the project

First, we need to create and download a Kotlin Multiplatform project from the Kotlin Multiplatform Wizard.

Choose Android and iOS as platforms and select Share UI (with Compose Multiplatform UI framework). Then hit the download button.

How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

After you’ve extracted the project, open it in Android Studio. The structure when opening the Project view will look like this:

How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Next, we’re going to install the Scanbot Compose Multiplatform Barcode Scanner SDK.

The 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.

// 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/")
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

In gradle/libs.versions.toml, set the Kotlin version to 2.1.0-Beta2 or higher.

How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Then add the dependency in app/build.gradle.kts:

implementation("io.scanbot:scanbot-sdk-compose-multiplatform:6.0.0")
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

With this, the Android app is already configured. However, building the iOS app requires further steps.

For instructions on how to install our SDK using XCFramework, please refer to our documentation.

In this tutorial, we’ll cover the installation process with CocoaPods.

Install the SDK using CocoaPods

To prepare the environment, follow the steps outlined in the Kotlin documentation.

Since we created our project using the Kotlin Multiplatform Wizard, we need to set up the CocoaPods integration manually.

Add the Kotlin CocoaPods Gradle plugin to the version catalogue in libs.versions.toml:

kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Then add the following alias to the plugins {} block in your root folder’s build.gradle.kts file:

alias(libs.plugins.kotlinCocoapods) apply false
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

And also add this alias to the plugins {} block in app/build.gradle.kts:

alias(libs.plugins.kotlinCocoapods)
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Now open app/build.gradle and add ScanbotBarcodeScannerSDK.

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
}
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Sync your project to create the required composeApp.podspec file.

How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

⚠️ If you haven’t already created a podfile, you will get a build error like this when syncing your project:

A problem was found with the configuration of task ':composeApp:podInstall' 
(type 'PodInstallTask').
  - In plugin 'org.jetbrains.kotlin.gradle.scripting.internal
  .ScriptingKotlinGradleSubplugin' type 'org.jetbrains.kotlin.gradle.targets
  .native.tasks.PodInstallTask' property 'podfile' specifies 
  file '/.../KotlinProject/iosApp/Podfile' which doesn't exist.

In that case, you need to create one.

First, navigate to the iosApp directory …

cd iosApp

… and run:

pod init

This will create a podfile inside the iosApp folder.

Now add the following code to Podfile:

platform :ios, '16.0'

target 'iosApp' do
    use_frameworks!

    # Local podspec from path
    pod 'composeApp', :path => '../composeApp/composeApp.podspec'
end
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Sync the project. It should now build successfully.

Build and run the iOS app

Next, open the file iosApp/iosApp.xcworkspace in Xcode. Set your signing and then build and run the app.

You will get the following error, which occurs when trying to use the embedAndSign task in a Kotlin Multiplatform project that also uses CocoaPods dependencies:

'embedAndSign' task can't be used in a project with dependencies to pods.

To solve this issue, add the following code to gradle.properties in your project’s root folder:

kotlin.apple.deprecated.allowUsingEmbedAndSignWithCocoaPodsDependencies=true
How to integrate the Compose Multiplatform Barcode Scanner SDK into your iOS app using CocoaPods

Sync and run the iOS app. Now it will build and run successfully.

🎉 Congratulations! You’ve integrated our Barcode Scanner SDK into your iOS using CocoaPods!

If you like, you can now create a scanning UI for your Compose Multiplatform app using the SDK’s Ready-to-Use UI Components. Or check out our example app on GitHub for a finished implementation of the SDK’s various scanning modes.

Should you have questions about this tutorial or ran into any issues, we’re happy to help! Just shoot us an email via tutorial-support@scanbot.io.

Happy coding!

Related blog posts

Experience our demo apps

Barcode Icon Art

Barcode Scanner SDK

Scan 1D and 2D barcodes reliably in under 0.04s. Try features like Batch Scanning, Scan & Count, and our AR Overlays.

Launch Web Demo

Scan the code to launch the web demo on your phone.

Web QR Code

Also available to download from:

Document Icon Art

Document Scanner SDK

Scan documents quickly and accurately with our free demo app. Create crisp digital scans in seconds.

Launch Web Demo

Scan the code to launch the web demo on your phone.

Black and white QR code. Scan this code for quick access to information.

Also available to download from:

Data_capture Icon Art

Data Capture Modules

Try fast, accurate data capture with our demo app. Extract data from any document instantly – 100% secure.

Launch Web Demo

Scan the code to launch the web demo on your phone.

Black and white QR code. Scan this quick response code with your smartphone.

Also available to download from: