> Task :opencv:compileDebugJavaWithJavac FAILED

Hello everyone! . I was trying to add OpenCV 4.6 to Android Studio Flamingo. However, I always get the same error which is the following:

It seems like Android Studio can’t detect the R module of OpenCV. I am new using OpenCV and I don’t know if I’m forgetting to perform some important step in the installation.
I would be very grateful if you help me solve the problem!

please, post code / errors as TEXT, screenshots of your ide are useless, thank you.

I am sorry. Here are the errors as text:

Task :opencv:compileDebugJavaWithJavac FAILED
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/AsyncServiceHelper.java:7: error: package org.opencv.engine does not exist
import org.opencv.engine.OpenCVEngineInterface;
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/AsyncServiceHelper.java:47: error: cannot find symbol
protected OpenCVEngineInterface mEngineService;
^
symbol: class OpenCVEngineInterface
location: class AsyncServiceHelper
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraGLSurfaceView.java:3: error: cannot find symbol
import org.opencv.R;
^
symbol: class R
location: package org.opencv
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraBridgeViewBase.java:5: error: cannot find symbol
import org.opencv.BuildConfig;
^
symbol: class BuildConfig
location: package org.opencv
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraBridgeViewBase.java:6: error: cannot find symbol
import org.opencv.R;
^
symbol: class R
location: package org.opencv
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/JavaCameraView.java:15: error: cannot find symbol
import org.opencv.BuildConfig;
^
symbol: class BuildConfig
location: package org.opencv
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/AsyncServiceHelper.java:161: error: package OpenCVEngineInterface does not exist
mEngineService = OpenCVEngineInterface.Stub.asInterface(service);
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraGLSurfaceView.java:48: error: package R does not exist
TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraGLSurfaceView.java:49: error: package R does not exist
int cameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraBridgeViewBase.java:74: error: package R does not exist
TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraBridgeViewBase.java:75: error: package R does not exist
if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraBridgeViewBase.java:78: error: package R does not exist
mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
^
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/CameraBridgeViewBase.java:429: error: cannot find symbol
if (BuildConfig.DEBUG)
^
symbol: variable BuildConfig
location: class CameraBridgeViewBase
/Users/kevin/AndroidStudioProjects/tesisOpenCv/opencv/java/src/org/opencv/android/JavaCameraView.java:302: error: cannot find symbol
if (BuildConfig.DEBUG)
^
symbol: variable BuildConfig
location: class JavaCameraView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
14 errors

Hi, I am also having same issue. Are you able to resolve it? if so, how did you do it, please share the steps with me.

Open Gradle Scripts/gradle.properties (Project Properties) and look near the bottom line. If you see the below is not there, add it.

"android.defaults.buildfeatures.buildconfig=true"

Then "org.opencv.BuildConfig" will be generated automatically at build time.