Cmake can't recognize ant and Java while build OpenCV with opencv_contrib

Hello everyone I am building OpenCV for Android with opencv_conitrb. I am using the following cmake:

cmake -GNinja -DCMAKE_MAKE_PROGRAM=c:/ninja/ninja -DCMAKE_INSTALL_PREFIX=E:/OpenCVAndroidSdk -DANDROID_PROJECTS_BUILD_TYPE="ANT" -DBUILD_ANDROID_PROJECTS=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_JAVA=ON -DBUILD_opencv_java=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_FAT_JAVA_LIB=ON -DBUILD_PYTHON=OFF -DINSTALL_ANDROID_EXAMPLES=OFF -DANDROID_EXAMPLES_WITH_LIBS=OFF -DBUILD_DOCS=OFF -DWITH_OPENCL=ON -DANDROID_NDK_HOST_X64=ON  -DANDROID_NDK=C:/Users/volce/AppData/Local/Android/Sdk/ndk/android-ndk-r25b/   -DANDROID_SDK=C:/Users/volce/AppData/Local/Android/Sdk -DCMAKE_TOOLCHAIN_FILE=C:/Users/volce/AppData/Local/Android/Sdk/ndk/android-ndk-r25b/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_static -DANDROID_ARM_NEON=ON -DANDROID_ABI=arm64-v8a -DANDROID_ABI=x86_64 -DANDROID_ABI=x86 -DANDROID_ABI=arm64-v8a -DANDROID_NDK_HOST_X64=ON -D BUILD_opencv_python3=OFF -D BUILD_opencv_python2=OFF  -D OPENCV_EXTRA_MODULES_PATH=E:/OpenCV/opencv_contrib-4.6.0/modules -DOPENCV_ENABLE_NONFREE=ON -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_SDK_TARGET=30  ..

But cmake can’t find java and ant:

--   OpenCV modules:
--     To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 alphamat cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2 python3 sfm ts viz
--     Applications:                -
--     Documentation:               NO
--     Non-free algorithms:         YES
--
--   Android NDK:                   C:/Users/volce/AppData/Local/Android/Sdk/ndk/android-ndk-r25b (ver 25.1.8937393)
--     Android ABI:                 arm64-v8a
--     NDK toolchain:               aarch64-linux-android-clang
--     STL type:                    c++_static
--     Native API level:            21
--   Android SDK:                   C:/Users/volce/AppData/Local/Android/Sdk (tools: 26.1.1 build tools: 33.0.0)
--     android tool:                C:/Users/volce/AppData/Local/Android/Sdk/tools/android.bat
--     Projects build scripts:      Ant/Eclipse compatible
--
--   GUI:                           NONE
--
--   Media I/O:
--     ZLib:                        z (ver 1.2.12)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.19.1)
--
--   OpenCL:                        YES (no extra features)
--     Include path:                E:/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python (for build):            C:/Users/volce/AppData/Local/Programs/Python/Python32/python.exe
--
--   Java:                          export all functions
--     ant:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    E:/OpenCVAndroidSdk
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done

I am using java 19. My environment variables:
JAVA_HOME: C:\Program Files\Java\jdk-18.0.1.1
ANT_HOME: C:\ant\bin
ANT_EXECUTABLE: C:\ant\bin\ant.bat

PATH:

  • C:\Program Files\Java\jdk-18.0.1.1\bin
  • C:\ant\bin

I use this

CMAKE_OPTIONS='-DBUILD_opencv_world:BOOL=OFF -DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_IPP=OFF -DWITH_MSMF=OFF -DCPU_DISPATCH='
cmake -DCMAKE_MAKE_PROGRAM=${ANDROID_NDK}/prebuilt/windows-x86_64/bin/make.exe  \
-DPYTHON3_EXECUTABLE:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/python.exe" \
-DEIGEN_INCLUDE_DIR=${installRepo}/eigen_v8a/include \
-DEigen3_DIR=${installRepo}/eigen_v8a/share/eigen3/cmake \
-DCeres_DIR=${installRepo}/ceres-solver_v8a/lib/cmake/ceres \
-Dglog_DIR:PATH=${installRepo}/glog_v8a/lib/cmake/glog -Dgflags_DIR:PATH=${installRepo}/gflags_v8a/lib/cmake/gflags \
-DGlog_DIR:PATH=${installRepo}/glog_v8a/lib/cmake/glog \
-DGLOG_INCLUDE_DIR=${installRepo}/glog_v8a/include \
-DANDROID_ABI=arm64-v8a \
-DWITH_CAROTENE:BOOL=OFF \
-DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi \
-DJAVA_AWT_INCLUDE_PATH:PATH="C:/Program Files/Java/jdk1.8.0_152/include" \
-DJAVA_AWT_INCLUDE_PATH:PATH="C:/Program Files/Java/jdk1.8.0_152/include" \
-DJAVA_AWT_LIBRARY:FILEPATH="C:/Program Files/Java/jdk1.8.0_152/lib/jawt.lib" \
-DJAVA_INCLUDE_PATH:PATH="C:/Program Files/Java/jdk1.8.0_152/include" \
-DJAVA_INCLUDE_PATH2:PATH="C:/Program Files/Java/jdk1.8.0_152/include/win32" \
-DJAVA_JVM_LIBRARY:FILEPATH="C:/Program Files/Java/jdk1.8.0_152/lib/jvm.lib" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
-DANDROID_SDK_ROOT:PATH=${ANDROID_HOME} \
-DANDROID_NATIVE_API_LEVEL=30 \
-DANDROID_ARM_NEON=ON \
-DBUILD_ANDROID_PROJECTS:BOOL=ON \
-DANT_EXECUTABLE:FILEPATH=f:/apache-ant-1.10.5/bin/ant.bat \
-DGRADLE_VERSION=7.5.1 \
-DKOTLIN_PLUGIN_VERSION=1.7.10 \
-G"$CMAKE_CONFIG_GENERATOR" \
$CMAKE_OPTIONS  -DOPENCV_ENABLE_NONFREE:BOOL=OFF \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DINSTALL_CREATE_DISTRIB=ON -DCMAKE_INSTALL_PREFIX=/g/lib/install/opencv  ../../"$RepoSource"

I get the following error:

BUILD FAILED
C:\Users\volce\AppData\Local\Android\Sdk\tools\ant\build.xml:649: The following error occurred while executing this line:
C:\Users\volce\AppData\Local\Android\Sdk\tools\ant\build.xml:655: null returned: -1073741819

I have switched to sdk tool 25.2, sdk platform tools 25, java 8

sdk tool 25.2, sdk platform tools 25, java 8, Does it work?