Home Page | Documentation & Guides | Showcase | API Reference | Developer Portal | My Lenses | Discord
Camera Kit brings the power of Snap's AR platform to your websites and mobile apps on iOS and Android. It has never been easier to create and deliver scalable, multi-platform AR experiences to meet your customers, wherever they are.
- Face Effects
- Body / Face / Hand Tracking
- World Tracking
- Background Segmentation
- Location AR
- and many more
- Integrate with Camera Kit com.snap.camerakit.Session, which allows to maintain full control over session configuration, management, and lifecycle
- Fetch and display your lenses
- Capture media
- Leverage Reference UI modules to quickly build Camera Kit based experiences
- Supports Android 5.0+ and SDK 21+
- Setup your Camera Kit application using Developer Portal
- Integrate Camera Kit SDK into your Android application
- Create AR experiences using Lens Studio and manage them using My Lenses site
All of the Camera Kit artifacts are published under a single version and it is possible to pick and choose the dependencies necessary for your specific project:
implementation "com.snap.camerakit:camerakit:$cameraKitVersion"
implementation "com.snap.camerakit:lenses-bundle:$cameraKitVersion"
implementation "com.snap.camerakit:support-camerax:$cameraKitVersion"
In order for Camera Kit to be able to communicate with remote services to get content such as lenses, app needs to provide Camera Kit its unique "API token", this can be found at Snap Developer Portal. The easiest way to do this is to define the token within the app's AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="com.snap.camerakit.api.token" android:value="REPLACE-THIS-WITH-YOUR-OWN-APP-SPECIFIC-VALUE" />
</application>
Camera Kit is built targeting Java8 bytecode which requires enabling Java8 compatibility (desugar) support via Android Gradle Plugin (AGP) compileOptions
for your app:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
For more information, see build configuration in camerakit-sample-full
build.gradle.
import com.snap.camerakit.support.camerax.CameraXImageProcessorSource
var imageProcessorSource = CameraXImageProcessorSource(
context = this, lifecycleOwner = this
)
imageProcessorSource.startPreview(true) // true = front camera , false = back
var cameraKitSession = Session(context = this) {
imageProcessorSource(imageProcessorSource)
attachTo(findViewById(R.id.camera_kit_stub))
}
You can find lens group IDs and specific lens IDs on My Lenses site
cameraKitSession.apply {
lenses.repository.observe(
LensesComponent.Repository.QueryCriteria.ById(LENS_ID, LENS_GROUP_ID)
) { result ->
result.whenHasFirst { requestedLens ->
lenses.processor.apply(requestedLens)
}
}
}
Session
instance is typically shared within a single Android application, service or activity lifecycle scope as Session
is costly in terms of memory and cpu resources it requires to operate. Once done with a Session
, It is essential to dispose it using Session#close
method which releases all the acquired resources in Camera Kit safe manner.
override fun onDestroy() {
cameraKitSession.close()
super.onDestroy()
}
This project includes several sample apps that demonstrate different approaches to integrating the Camera Kit SDK:
camerakit-sample-basic
demonstrates simplest and bare minimum way to integrate Camera Kit.camerakit-sample-full
contains a fully functioning camera capture with lenses and preview flow.camerakit-sample-custom-video
demonstrates how to set up a custom video/audio encoding and audio source implementation.camerakit-sample-custom-input
demonstrates how to setup a custom input to the Camera Kit's processing pipeline.camerakit-sample-simple
demonstrates how to setup a simple, Camera Kit powered, camera capture flow via the standalone, batteries-includedCameraActivity
.camerakit-sample-dynamic
demonstrates how to dynamically load Camera Kit SDK as a dynamic feature module (DFM) as well as a standalone apk.camerakit-sample-custom-carousel
demonstrates how to provide your own carousel and preview screen to Camera Kit.
Applications can receive lenses from Lens Studio using the P2D feature. See P2D Integration.
The following is a list of common issues and suggestions on how to troubleshoot them when integrating Camera Kit into your own app.
- Check that your device is supported by Camera Kit using
Sessions#supported
method. The minimum OpenGLES version that Camera Kit supports is 3.0. - Check that a camera based
Source<ImageProcessor>
such asCameraXImageProcessorSource
is provided to theSession.Builder
. If you cannot provide an implementation ofSource<ImageProcessor>
then make sure to connect aSurfaceTexture
based input to the currentSession.processor
. - If no
ViewStub
is provided to theSession.Builder
then Camera Kit does not attempt to render any views such as lenses carousel as well as camera preview. To see camera preview without any other Camera Kit views, aTextureView
,SurfaceTexture
orSurface
based output must be connected to the currentSession.processor
. - If a non-null
ViewStub
is provided to theSession.Builder
check (using Layout Inspector) that the layout dimensions are more than 0 when theViewStub
gets inflated. The Camera Kit's root view that gets inflated from the providedViewStub
inherits layout parameters set on theViewStub
, check thatmatch_parent
or other parameters are applicable to your layout. - Compare versions of dependencies of your app to the Camera Kit sample apps. If dependency versions differ, for example the
camerakit-sample-full
usesandroidx.constraintlayout:constraintlayout:1.1.3
while your app usesandroidx.constraintlayout:constraintlayout:2.0.0
, it is possible that code ported from Camera Kit sample to your app may not work as expected.
- Attach debugger to your app, enable Java exception breakpoints and build a
Session
while checking that there are no unexpected exceptions with stacktraces related to Camera Kit. - Attach debugger to your app, pause all threads and export their state into a text file - check that there are no deadlocked threads related to Camera Kit.
- Check Camera Kit FAQ page.
- Need extra support? Check our support page