I am working in an android project with Android Studio 2.2 that uses OpenCV 3.1.0 library. I imported the library according to this answer. The situation is the following:
- When I compile the project for a device with API >= 21 (exactly API 23), everything goes well.
- When I compile the project for a device with API < 21 (exactly API 19, the minimum API that I want to support), I get the following compilation error:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithInstantRunForDebug'. > java.lang.ClassNotFoundException: android.hardware.camera2.CameraAccessException * Try: Run with --info or --debug option to get more log output. * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithInstantRunForDebug'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)...
I found these similar questions:
- Error: package android.hardware.camera2 does not exist OpenCV
- Can't import import android.hardware.camera2 classes
In both of them the solution was to set the
compileSdkVersion to minimum 21 (the version where
camera2 API was introduced) and make sure that
build.gradle files of the project and OpenCV match.
Unfortunately, it does not work for me. I still get the same error. Any idea?
My code is available here: Github repository.
Thanks for your help!