Affectiva affdex-sdk works with Android SDK 22 only?



I am trying out the github examples referenced in the Affectiva AI docs.

The examples work with the gradle configuration they come with:


apply plugin: ''

android {

    compileSdkVersion 22
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        setProperty("archivesBaseName", "$$versionName")
        applicationId "com.affectiva.cameradetectordemo"
        versionName "3.2.0-01"
    buildTypes {
        release {
            minifyEnabled true
    buildToolsVersion '27.0.3'

dependencies {

The problem is, the examples work ONLY with compileSdkVersion and targetSdkVersion both set to 22.
When i enter anything higher, 23 to 27, the apps compile but when i want to start the camera from inside the app, the app crashes with the Error Message

java.lang.IllegalStateException: Camera is unavailable.


  1. Why are the Affectiva examples only working with SDK version 22?
  2. How can i use the affdex-sdk with a current version of the Android SDK?

Thanks for your help!


Android introduced the runtime permissions feature in API level 23. An app that targets 23+ must implement runtime permissions logic and request camera permission in order to access the camera.

The purpose of the sample you are referencing is to demonstrate use of the Affectiva SDK, so to avoid the need to add a bunch of runtime permission logic which would be irrelevant to that purpose, it targets API level 22.


Thank you, that was helpful!

To avoid the permission hassle i used this google library: