Not able to build Opencv 4.5.1 for android

I am trying to build opencv 4.5.1 for android on Windows.
I followed the steps mentioned in https://amin-ahmadi.com/2020/09/27/how-to-build-opencv-3-4-11-for-native-android-development-using-powershell-windows/

I am using android ndk 17.2.4988734.

But i am getting the following error
D:\opencv\opencv_4_5_1\opencv\modules\core\src\system.cpp: In function ‘T cv::parseOption(const string&) [with T = unsigned int; std::string = std::basic_string]’:
D:\opencv\opencv_4_5_1\opencv\modules\core\src\system.cpp:1902:24: error: ‘stoull’ is not a member of 'std’
size_t v = (size_t)std::stoull(valueStr);
^
modules\world\CMakeFiles\opencv_world.dir\build.make:1132: recipe for target 'modules/world/CMakeFiles/opencv_world.dir//core/src/system.cpp.o’ failed
mingw32-make[2]: *** [modules/world/CMakeFiles/opencv_world.dir/
/core/src/system.cpp.o] Error 1
CMakeFiles\Makefile2:1923: recipe for target ‘modules/world/CMakeFiles/opencv_world.dir/all’ failed
mingw32-make[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
Makefile:180: recipe for target ‘all’ failed
mingw32-make: *** [all] Error 2

I was able to build 3.4.11 successfully using the above method.

Please suggest what changes i have to do to build it.

Like this it works in my configuration (opencv 4.5.1 and ANDROID_NDK=f:\android_ndk\android-ndk-r18b)

myRepo=$(pwd)
RepoSource=opencv
CMAKE_CONFIG_GENERATOR="Ninja"
CMAKE_CONFIG_GENERATOR="MinGW Makefiles"
ANDROID_NDK=/F/Android_ndk/android-ndk-r18b 
ANDROID_HOME=/F/Data_SDK_Android
installRepo=/g/lib/install
cd Build/opencvandroidv7a
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=ON -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  \
-DWITH_EIGEN:BOOL=ON \
-DGLOG_LIBRARY=/G/Lib/install/glog_v7a/lib/libglog.a \
-DEigen3_DIR:PATH=/g/lib/install/Eigen3/share/eigen3/cmake \
-Dglog_DIR:PATH=/g/lib/Install/glog_v7a/lib/cmake/glog \
-Dgflags_DIR:PATH=/g/lib/Install/gflags_v7a/lib/cmake/gflags \
-DGLOG_INCLUDE_DIR=/g/lib/install/glog_v7a/include \
-DCeres_DIR=/g/lib/install/ceres-solver_v7a/lib/cmake/Ceres \
-DANDROID_ABI=armeabi-v7a \
-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=/F/Data_SDK_Android \
-DANDROID_NATIVE_API_LEVEL=25 \
-DANDROID_ARM_NEON=ON \
-DBUILD_ANDROID_PROJECTS:BOOL=ON \
-DANT_EXECUTABLE:FILEPATH=f:/apache-ant-1.10.5/bin/ant.bat \
-G"$CMAKE_CONFIG_GENERATOR" \
$CMAKE_OPTIONS -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DOPENCV_ENABLE_NONFREE:BOOL=OFF \
-DINSTALL_CREATE_DISTRIB=ON -DCMAKE_INSTALL_PREFIX=/g/lib/install/opencv  ../../"$RepoSource"
cd ..
cmake --build opencvandroidv7a  --config release 
cmake --build opencvandroidv7a  --target install --config release 
cd ..

Hi laurent,

Thanks for the quick reply. But with android-ndk-r18b, i get the following error
CMake Error at platforms/android/android.toolchain.cmake:628 (message):
Could not find any working toolchain in the NDK. Probably your Android NDK
is broken.
Call Stack (most recent call first):
D:/opencv/cmake-3.19.3-win64-x64/share/cmake-3.19/Modules/CMakeDetermineSystem.cmake:123 (include)
CMakeLists.txt:99 (enable_language)

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
– Configuring incomplete, errors occurred!

I am new to opencv. Am i missing something. For me only the lower versions of ndk are working. For the latest ndk, i get the ble mentioned error

Am i missing anything here

Can you please paste your nice script on pastebin or attache it as file?

It is broken for copy paste.

Thank you a lot.

Weird Hope now it’s good