Skip to content

Snapchat/camera-kit-android-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

distort hair_simulation chane_physics try_on 3d_hand_tracking wrist_wear_try_on eye_wear_try_on true_size_object landmarkers

Features

AR Capabilities

  • Face Effects
  • Body / Face / Hand Tracking
  • World Tracking
  • Background Segmentation
  • Location AR
  • and many more

Android SDK

  • 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+

Integration Steps

  1. Setup your Camera Kit application using Developer Portal
  2. Integrate Camera Kit SDK into your Android application
  3. Create AR experiences using Lens Studio and manage them using My Lenses site

Configuration

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.

Usage

Initializing Image Processor and Preview

    import com.snap.camerakit.support.camerax.CameraXImageProcessorSource

    var imageProcessorSource = CameraXImageProcessorSource(
            context = this, lifecycleOwner = this
    )

    imageProcessorSource.startPreview(true) // true = front camera , false = back

Initializing Camera Kit Session

    var cameraKitSession = Session(context = this) {
        imageProcessorSource(imageProcessorSource)
        attachTo(findViewById(R.id.camera_kit_stub))
    }

Applying AR Lens

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)
            }
        }
    }

Lifecycle

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()
    }

Samples

This project includes several sample apps that demonstrate different approaches to integrating the Camera Kit SDK:

Development

Push To Device (P2D)

Applications can receive lenses from Lens Studio using the P2D feature. See P2D Integration.

Troubleshooting

The following is a list of common issues and suggestions on how to troubleshoot them when integrating Camera Kit into your own app.

Camera preview is black

  • 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 as CameraXImageProcessorSource is provided to the Session.Builder. If you cannot provide an implementation of Source<ImageProcessor> then make sure to connect a SurfaceTexture based input to the current Session.processor.
  • If no ViewStub is provided to the Session.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, a TextureView, SurfaceTexture or Surface based output must be connected to the current Session.processor.
  • If a non-null ViewStub is provided to the Session.Builder check (using Layout Inspector) that the layout dimensions are more than 0 when the ViewStub gets inflated. The Camera Kit's root view that gets inflated from the provided ViewStub inherits layout parameters set on the ViewStub, check that match_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 uses androidx.constraintlayout:constraintlayout:1.1.3 while your app uses androidx.constraintlayout:constraintlayout:2.0.0, it is possible that code ported from Camera Kit sample to your app may not work as expected.

Nothing works 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published