Affectiva affdex-sdk works with Android SDK 22 only

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

See: Affectiva Android example on github

The examples work, shipping with the following project gradle configuration:

build.gradle

apply plugin: 'com.android.application'

android {


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

dependencies {
    implementation('com.affectiva.android:affdexsdk:3.+')
}

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.

Questions:

  1. Why is 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!

1 answer

  • answered 2018-05-28 20:27 Andy Dennie

    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.