If you want to build from source you can take the whole OpenCV repository:
You need to have CMake and Android-NDK. If you’re using Android Studio, it can manage NDK for you (you just go to SDK manager and you will see NDK checkbox in SDK Tools tab). NDK will be in the ANDROID_SDK_LOCATION/ndk/22.0.7026061 or a different version.
Inside opencv/ directory you can create a new dir called build/ (or any name you like).
Inside the build/ directory you can invoke the cmake command.
#!/usr/bin/env bash
export ANDROID_NDK="$ANDROID_SDK/ndk/22.0.7026061"
# android.toolchain.cmake in opencv source does not work so
# `.cmake` file included in the NDK is used.
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
-DBUILD_EXAMPLES=OFF \
-DBUILD_ANDROID_EXAMPLES=ON \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF
After build/ directory is configured you can just run make inside it.
After that finishes you should have a build/opencv_android directory that you can open inside Android Studio and build each separate sample and install it on your phone.
You might only need DNN or other modules that are shown in the samples and you can build only with them by adding a -DBUILD_LIST=dnn to script above.
If you don’t care about the build time you can just do a build with everything.