OpenCV Java SDK not building in React Native app as Native Module: android packages and symbols not existing

System Information

OpenCV version: 4.8.0
OS: Windows 11
Java SDK: 11.0.20
Gradle version: 6.9.4

Detailed description

I have a React Native app where I want to add the OpenCV Java SDK as a Native Module. I have tried various tutorials to make this work, and now I have done all the steps described in this StackOverflow answer . However, when I try to run the project, I get a > Task :opencv:compileDebugJavaWithJavac FAILED with the logs below showing that basic packages as andorid.content and android.util do not exist.

I could build just fine prior to adding openCV, and these errors only show up for this openCV task. How do I fix this?

Android Studio Build Output log
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:9: error: package android.content does not exist
import android.content.ComponentName;
                      ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:10: error: package android.content does not exist
import android.content.Context;
                      ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:11: error: package android.content does not exist
import android.content.Intent;
                      ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:12: error: package android.content does not exist
import android.content.ServiceConnection;
                      ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:13: error: package android.net does not exist
import android.net.Uri;
                  ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:14: error: package android.os does not exist
import android.os.IBinder;
                 ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:15: error: package android.os does not exist
import android.os.RemoteException;
                 ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:16: error: package android.util does not exist
import android.util.Log;
                   ^
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:20: error: cannot find symbol
    public static boolean initOpenCV(String Version, final Context AppContext,
                                                           ^
  symbol:   class Context
  location: class AsyncServiceHelper
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:38: error: cannot find symbol
    protected AsyncServiceHelper(String Version, Context AppContext, LoaderCallbackInterface Callback)
                                                 ^
  symbol:   class Context
  location: class AsyncServiceHelper
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:50: error: cannot find symbol
    protected Context mAppContext;
              ^
  symbol:   class Context
  location: class AsyncServiceHelper
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:54: error: cannot find symbol
    protected static boolean InstallServiceQuiet(Context context)
                                                 ^
  symbol:   class Context
  location: class AsyncServiceHelper
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:71: error: cannot find symbol
    protected static void InstallService(final Context AppContext, final LoaderCallbackInterface Callback)
                                               ^
  symbol:   class Context
  location: class AsyncServiceHelper
C:\PATH_TO_MY_APP\android\opencv\java\src\org\opencv\android\AsyncServiceHelper.java:156: error: cannot find symbol
    protected ServiceConnection mServiceConnection = new ServiceConnection()
              ^
  symbol:   class ServiceConnection
  location: class AsyncServiceHelper

Steps to reproduce

Follow the steps in this StackOverflow answer and try to run in debug mode in Android Studio

I have not tried the steps above & do not have experience with react-native but I see from the post that you are using android studio to set up the java side of the project. Can you check the steps mentioned in this post: An exercise in frustration ? This worked smoothly for me.