Skip to content

Installation

Add CameraK to your Kotlin Multiplatform project in under 5 minutes.

Prerequisites

  • Kotlin 1.9.0 or higher
  • Gradle 8.0 or higher
  • Target platforms:
    • Android: API 21+ (Android 5.0)
    • iOS: iOS 13.0+
    • Desktop: JDK 11+

Step 1: Add Dependencies

Using Gradle (Kotlin DSL)

Add to your build.gradle.kts:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.kashif-mehmood-km:camerak:0.2.0")
        }
    }
}

Using Version Catalog

Add to gradle/libs.versions.toml:

[versions]
camerak = "0.2.0"

[libraries]
camerak = { module = "io.github.kashif-mehmood-km:camerak", version.ref = "camerak" }

Then in build.gradle.kts:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation(libs.camerak)
        }
    }
}

Android-Only Project

dependencies {
    implementation("io.github.kashif-mehmood-km:camerak:0.2.0")
}

Step 2: Platform-Specific Setup

Android

Add permissions to AndroidManifest.xml:

<manifest>
    <uses-feature android:name="android.hardware.camera" android:required="true" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="28" />
</manifest>

No additional configuration needed — CameraX is included automatically.

iOS

Add usage descriptions to Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app needs camera access to capture photos</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs to save photos to your library</string>

Desktop (JVM)

No additional setup required. JavaCV dependencies are included automatically.

Step 3: Sync Project

Run Gradle sync:

./gradlew build

Optional: Add Plugins

QR Scanner Plugin

dependencies {
    implementation("io.github.kashif-mehmood-km:qr_scanner_plugin:0.2.0")
}

OCR Plugin

dependencies {
    implementation("io.github.kashif-mehmood-km:ocr_plugin:0.2.0")
}

Image Saver Plugin

dependencies {
    implementation("io.github.kashif-mehmood-km:image_saver_plugin:0.2.0")
}

Verify Installation

Create a simple test to verify:

@Composable
fun TestCameraScreen() {
    val permissions = providePermissions()
    val stateHolder = rememberCameraKState(permissions = permissions)
    val cameraState by stateHolder.cameraState.collectAsStateWithLifecycle()

    when (cameraState) {
        is CameraKState.Ready -> Text("✅ CameraK is ready!")
        is CameraKState.Error -> Text("❌ Error: ${cameraState.exception.message}")
        CameraKState.Initializing -> CircularProgressIndicator()
    }
}

If you see "CameraK is ready!" — you're all set!

Troubleshooting

Android: "CameraX not found"

Ensure you're using API 21+:

android {
    defaultConfig {
        minSdk = 21
    }
}

iOS: "Camera permission denied"

Check your Info.plist has NSCameraUsageDescription.

Desktop: "No camera detected"

Ensure a webcam is connected and accessible by your OS.

Next Steps