Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Generate custom opencv .so for Android

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

click to hide/show revision 2
retagged

updated 2019-10-23 09:31:22 -0600

berak gravatar image

Generate custom opencv .so for Android

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

Generate custom opencv .so for Android

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

Generate custom opencv .so for AndroidGenerating libopencv_java4.so throws: Unable to recognise the format of the input file

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

UPDATE 25/10/19:

Following mvuori's suggestion I tried to apply many different examples for building OpenCV in Windows, and I've managed to generate core and imgproc .so; However as I need to build libopencv_java.so for each valid Android architecture I made some changes to what I was doing, but now it always fail at 99%

This is the error i get:

C:\MinGW\bin\strip.exe: Unable to recognise the format of the input file `C:/Users/mauro/Downloads/opencv-4.1.2/build/jni/armeabi-v7a/libopencv_java4.so' modules\java\jni\CMakeFiles\opencv_java.dir\build.make:174: recipe for target 'jni/armeabi-v7a/libopencv_java4.so' failed mingw32-make[2]: * [jni/armeabi-v7a/libopencv_java4.so] Error 1 mingw32-make[2]: Deleting file 'jni/armeabi-v7a/libopencv_java4.so' CMakeFiles\Makefile2:1536: recipe for target 'modules/java/jni/CMakeFiles/opencv_java.dir/all' failed mingw32-make[1]: [modules/java/jni/CMakeFiles/opencv_java.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: * [all] Error 2

This is my CMake configuration:

General configuration for OpenCV 4.1.2 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2019-10-25T23:25:56Z
    Host:                        Windows 10.0.18362 AMD64
    Target:                      Android 1 armv7-a
    CMake:                       3.16.0-rc2
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/MinGW/bin/mingw32-make.exe
    Configuration:               Release

  CPU/HW features:
    Baseline:
      requested:                 DETECT

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe  (ver 8.0)
    C++ flags (Release):         -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C++ flags (Debug):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    C Compiler:                  C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
    C flags (Release):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C flags (Debug):             -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m log
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 core imgproc java
    Disabled:                    world
    Disabled by dependency:      calib3d dnn features2d flann highgui imgcodecs ml objdetect photo stitching ts video videoio
    Unavailable:                 gapi js python2 python3
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Android NDK:                   C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570 (ver 20.0.5594570)
    Android ABI:                 armeabi-v7a
    NDK toolchain:               arm-linux-androideabi-clang
    STL type:                    c++_static
    Native API level:            17
  Android SDK:                   not used, projects are not built

  GUI: 

  Media I/O: 
    ZLib:                        C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/arm-linux-androideabi/libz.a (ver 1.2.7)
    JPEG:                        build-libjpeg-turbo (ver 2.0.2-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:

  Parallel framework:            pthreads

  Trace:                         YES (built-in)

  Other third-party libraries:
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  Python (for build):            C:/Users/mauro/AppData/Local/Programs/Python/Python38/python.exe

  Java:                          
    ant:                         C:/ant/bin/ant.bat (ver )
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    C:/Users/mauro/Downloads/opencv-4.1.2/build/install

Generating libopencv_java4.so throws: Unable to recognise the format of the input file

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

UPDATE 25/10/19:

Following mvuori's suggestion I tried to apply many different examples for building OpenCV in Windows, and I've managed to generate core and imgproc .so; However as I need to build libopencv_java.so for each valid Android architecture I made some changes to what I was doing, but now it always fail at 99%

This is the error i get:

C:\MinGW\bin\strip.exe: Unable to recognise the format of the input file `C:/Users/mauro/Downloads/opencv-4.1.2/build/jni/armeabi-v7a/libopencv_java4.so' modules\java\jni\CMakeFiles\opencv_java.dir\build.make:174: recipe for target 'jni/armeabi-v7a/libopencv_java4.so' failed mingw32-make[2]: * [jni/armeabi-v7a/libopencv_java4.so] Error 1 mingw32-make[2]: Deleting file 'jni/armeabi-v7a/libopencv_java4.so' CMakeFiles\Makefile2:1536: recipe for target 'modules/java/jni/CMakeFiles/opencv_java.dir/all' failed mingw32-make[1]: [modules/java/jni/CMakeFiles/opencv_java.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: * [all] Error 2

This is my CMake configuration:

General configuration for OpenCV 4.1.2 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2019-10-25T23:25:56Z
    Host:                        Windows 10.0.18362 AMD64
    Target:                      Android 1 armv7-a
    CMake:                       3.16.0-rc2
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/MinGW/bin/mingw32-make.exe
    Configuration:               Release

  CPU/HW features:
    Baseline:
      requested:                 DETECT

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe  (ver 8.0)
    C++ flags (Release):         -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C++ flags (Debug):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    C Compiler:                  C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
    C flags (Release):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C flags (Debug):             -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m log
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 core imgproc java
    Disabled:                    world
    Disabled by dependency:      calib3d dnn features2d flann highgui imgcodecs ml objdetect photo stitching ts video videoio
    Unavailable:                 gapi js python2 python3
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Android NDK:                   C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570 (ver 20.0.5594570)
    Android ABI:                 armeabi-v7a
    NDK toolchain:               arm-linux-androideabi-clang
    STL type:                    c++_static
    Native API level:            17
  Android SDK:                   not used, projects are not built

  GUI: 

  Media I/O: 
    ZLib:                        C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/arm-linux-androideabi/libz.a (ver 1.2.7)
    JPEG:                        build-libjpeg-turbo (ver 2.0.2-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:

  Parallel framework:            pthreads

  Trace:                         YES (built-in)

  Other third-party libraries:
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  Python (for build):            C:/Users/mauro/AppData/Local/Programs/Python/Python38/python.exe

  Java:                          
    ant:                         C:/ant/bin/ant.bat (ver )
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    C:/Users/mauro/Downloads/opencv-4.1.2/build/install

Generating libopencv_java4.so throws: Unable to recognise the format of the input fileGenerate custom opencv .so for Android [Windows] [Solved]

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

UPDATE 25/10/19:

Following mvuori's suggestion I tried to apply many different examples for building OpenCV in Windows, and I've managed to generate core and imgproc .so; However as I need to build libopencv_java.so for each valid Android architecture I made some changes to what I was doing, but now it always fail at 99%

This is the error i get:

C:\MinGW\bin\strip.exe: Unable to recognise the format of the input file `C:/Users/mauro/Downloads/opencv-4.1.2/build/jni/armeabi-v7a/libopencv_java4.so' modules\java\jni\CMakeFiles\opencv_java.dir\build.make:174: recipe for target 'jni/armeabi-v7a/libopencv_java4.so' failed mingw32-make[2]: * [jni/armeabi-v7a/libopencv_java4.so] Error 1 mingw32-make[2]: Deleting file 'jni/armeabi-v7a/libopencv_java4.so' CMakeFiles\Makefile2:1536: recipe for target 'modules/java/jni/CMakeFiles/opencv_java.dir/all' failed mingw32-make[1]: [modules/java/jni/CMakeFiles/opencv_java.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: * [all] Error 2

This is my CMake configuration:

General configuration for OpenCV 4.1.2 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2019-10-25T23:25:56Z
    Host:                        Windows 10.0.18362 AMD64
    Target:                      Android 1 armv7-a
    CMake:                       3.16.0-rc2
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/MinGW/bin/mingw32-make.exe
    Configuration:               Release

  CPU/HW features:
    Baseline:
      requested:                 DETECT

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe  (ver 8.0)
    C++ flags (Release):         -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C++ flags (Debug):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    C Compiler:                  C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
    C flags (Release):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C flags (Debug):             -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m log
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 core imgproc java
    Disabled:                    world
    Disabled by dependency:      calib3d dnn features2d flann highgui imgcodecs ml objdetect photo stitching ts video videoio
    Unavailable:                 gapi js python2 python3
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Android NDK:                   C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570 (ver 20.0.5594570)
    Android ABI:                 armeabi-v7a
    NDK toolchain:               arm-linux-androideabi-clang
    STL type:                    c++_static
    Native API level:            17
  Android SDK:                   not used, projects are not built

  GUI: 

  Media I/O: 
    ZLib:                        C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/arm-linux-androideabi/libz.a (ver 1.2.7)
    JPEG:                        build-libjpeg-turbo (ver 2.0.2-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:

  Parallel framework:            pthreads

  Trace:                         YES (built-in)

  Other third-party libraries:
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  Python (for build):            C:/Users/mauro/AppData/Local/Programs/Python/Python38/python.exe

  Java:                          
    ant:                         C:/ant/bin/ant.bat (ver )
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    C:/Users/mauro/Downloads/opencv-4.1.2/build/install

Generate custom opencv .so for Android [Windows] [Windows 10] [Solved]

Hello, I recently started using opencv for Android in a project, however I need to reduce apk size, and so i found install-opencv-on-android-tiny-and-optimized

Apparently is possible to generate the opencv.so files with fewer modules, like core and imgproc in the example above, which is just what I need, but i don't know how to do all that since I'm in Windows 10.

Can I use the the opencv 4.1.2 (Which is the version I'm using in my project)? Can I use the latest Android NDK? Can I compile against the latest Android API (29 currently) ?

If someone could point me in the right direction it would be really great.

UPDATE 25/10/19:29/10/19:

Following mvuori's suggestion I tried I've successfully generated my custom opencv .so look down below to apply many different examples for building OpenCV in Windows, and I've managed to generate core and imgproc .so; However as I need to build libopencv_java.so for each valid Android architecture I made some changes to check what I was doing, but now it always fail at 99%did.

This is the error i get:

C:\MinGW\bin\strip.exe: Unable to recognise the format of the input file `C:/Users/mauro/Downloads/opencv-4.1.2/build/jni/armeabi-v7a/libopencv_java4.so' modules\java\jni\CMakeFiles\opencv_java.dir\build.make:174: recipe for target 'jni/armeabi-v7a/libopencv_java4.so' failed mingw32-make[2]: * [jni/armeabi-v7a/libopencv_java4.so] Error 1 mingw32-make[2]: Deleting file 'jni/armeabi-v7a/libopencv_java4.so' CMakeFiles\Makefile2:1536: recipe for target 'modules/java/jni/CMakeFiles/opencv_java.dir/all' failed mingw32-make[1]: [modules/java/jni/CMakeFiles/opencv_java.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: * [all] Error 2

This is my CMake configuration:

General configuration for OpenCV 4.1.2 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2019-10-25T23:25:56Z
    Host:                        Windows 10.0.18362 AMD64
    Target:                      Android 1 armv7-a
    CMake:                       3.16.0-rc2
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/MinGW/bin/mingw32-make.exe
    Configuration:               Release

  CPU/HW features:
    Baseline:
      requested:                 DETECT

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe  (ver 8.0)
    C++ flags (Release):         -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C++ flags (Debug):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security     -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    C Compiler:                  C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
    C flags (Release):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Oz -DNDEBUG   -DNDEBUG
    C flags (Debug):             -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info   -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack   -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m log
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 core imgproc java
    Disabled:                    world
    Disabled by dependency:      calib3d dnn features2d flann highgui imgcodecs ml objdetect photo stitching ts video videoio
    Unavailable:                 gapi js python2 python3
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Android NDK:                   C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570 (ver 20.0.5594570)
    Android ABI:                 armeabi-v7a
    NDK toolchain:               arm-linux-androideabi-clang
    STL type:                    c++_static
    Native API level:            17
  Android SDK:                   not used, projects are not built

  GUI: 

  Media I/O: 
    ZLib:                        C:/Users/mauro/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/arm-linux-androideabi/libz.a (ver 1.2.7)
    JPEG:                        build-libjpeg-turbo (ver 2.0.2-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:

  Parallel framework:            pthreads

  Trace:                         YES (built-in)

  Other third-party libraries:
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  Python (for build):            C:/Users/mauro/AppData/Local/Programs/Python/Python38/python.exe

  Java:                          
    ant:                         C:/ant/bin/ant.bat (ver )
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    C:/Users/mauro/Downloads/opencv-4.1.2/build/install