Repository: kivy/python-for-android

Issue:
On Virtual Machine, this error arises when openCV is filled in the requirement in the spec file 
```
[INFO]:    python2 already patched, skipping
[INFO]:    Prebuilding numpy for armeabi-v7a
[INFO]:    numpy has no prebuild_armeabi_v7a, skipping
[WARNING]: Numpy is built assuming the archiver name is arm-linux-androideabi-ar, which may not always be true!
[INFO]:    Applying patches for numpy[armeabi-v7a]
[INFO]:    numpy already patched, skipping
[INFO]:    Prebuilding sdl2 for armeabi-v7a
[INFO]:    sdl2 has no prebuild_armeabi_v7a, skipping
[INFO]:    Applying patches for sdl2[armeabi-v7a]
[INFO]:    sdl2 already patched, skipping
[INFO]:    Prebuilding six for armeabi-v7a
[INFO]:    six has no prebuild_armeabi_v7a, skipping
[INFO]:    Prebuilding opencv for armeabi-v7a
[INFO]:    Applying patches for opencv[armeabi-v7a]
[INFO]:    Applying patch patches/p4a_build-2.4.10.1.patch
[INFO]:    -> running patch -t -d /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv -p1 -i /home/kivy/Desktop/Ca...(and 127 more)
           working: 2 out of 2 hunks ignored                                                                                                 Exception in thread background thread for pid 28277:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 2170, in background_thread
    handle_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1929, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
ErrorReturnCode_1: 

  RAN: /usr/bin/patch -t -d /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv -p1 -i /home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/recipes/opencv/patches/p4a_build-2.4.10.1.patch

  STDOUT:
patching file cmake/OpenCVDetectPython.cmake
Hunk #1 FAILED at 36.
Hunk #2 FAILED at 51.
Hunk #3 FAILED at 117.
3 out of 3 hunks FAILED -- saving rejects to file cmake/OpenCVDetectPython.cmake.rej
patching file modules/python/CMakeLists.txt
Hunk #1 FAILED at 5.
1 out of 1 hunk FAILED -- saving rejects to file modules/python/CMakeLists.txt.rej
can't find file to patch at input line 49
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp
|index 84db3e1..4222526 100644
|--- a/modules/androidcamera/src/camera_activity.cpp
|+++ b/modules/androidcamera/src/camera_activity.cpp
--------------------------
No file to patch.  Skipping patch.
2 out of 2 hunks ignored


  STDERR:


[INFO]:    STDOUT (last 10 lines of 19):
	Perhaps you used the wrong -p or --strip option?	
The text leading up to this was:	
--------------------------	
|diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp	
|index 84db3e1..4222526 100644	
|--- a/modules/androidcamera/src/camera_activity.cpp	
|+++ b/modules/androidcamera/src/camera_activity.cpp	
--------------------------	
No file to patch.  Skipping patch.	
2 out of 2 hunks ignored
[INFO]:    STDERR:
	
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 978, in <module>
    main()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 975, in main
    ToolchainCL()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 512, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 149, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 193, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "pythonforandroid/build.py", line 565, in build_recipes
    recipe.prebuild_arch(arch)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/recipes/opencv/__init__.py", line 22, in prebuild_arch
    self.apply_patches(arch)
  File "pythonforandroid/recipe.py", line 486, in apply_patches
    arch.arch)
  File "pythonforandroid/recipe.py", line 194, in apply_patch
    "-i", filename, _tail=10)
  File "pythonforandroid/logger.py", line 175, in shprint
    for line in output:
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 720, in next
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 651, in wait
    self.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /usr/bin/patch -t -d /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv -p1 -i /home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/recipes/opencv/patches/p4a_build-2.4.10.1.patch

  STDOUT:
patching file cmake/OpenCVDetectPython.cmake
Hunk #1 FAILED at 36.
Hunk #2 FAILED at 51.
Hunk #3 FAILED at 117.
3 out of 3 hunks FAILED -- saving rejects to file cmake/OpenCVDetectPython.cmake.rej
patching file modules/python/CMakeLists.txt
Hunk #1 FAILED at 5.
1 out of 1 hunk FAILED -- saving rejects to file modules/python/CMakeLists.txt.rej
can't find file to patch at input line 49
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp
|index 84db3e1..4222526 100644
|--- a/modules/androidcamera/src/camera_activity.cpp
|+++ b/modules/androidcamera/src/camera_activity.cpp
--------------------------
No file to patch.  Skipping patch.
2 out of 2 hunks ignored


  STDERR:

# Command failed: /usr/bin/python -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=kivy,opencv --arch armeabi-v7a --copy-libs --color=always --storage-dir=/home/kivy/Desktop/Cam/.buildozer/android/platform/build

```


Discussion:
So basically like the source code of opencv changed or like the patch moved. Which version of opencv did you pin on your `buildozer.spec`? Could you share the spec file?
@AndreMiras This is my spec file:
[buildozer.txt](https://github.com/kivy/python-for-android/files/2217318/buildozer.txt)

I gave it a try and it seems to work OK for me, see below:
```
[INFO]:    Prebuilding opencv for armeabi-v7a
[INFO]:    Applying patches for opencv[armeabi-v7a]
[INFO]:    Applying patch patches/p4a_build-2.4.10.1.patch
[INFO]:    -> running patch -t -d /home/andre/workspace/tests/p4a/issue-1313/.buildozer/android/platform/buil...(and 222 more)
                                                                     [INFO]:    -> running touch /home/andre/workspace/tests/p4a/issue-1313/.buildozer/android/platform/build/buil...(and 49 more)
[INFO]:    Applying patches for opencv[armeabi-v7a]
[INFO]:    opencv already patched, skipping
```
Perhaps your opencv archive didn't unpack properly. I would recommend you to take a look here `.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/`.
Also readying the `.rej` files should give you other hints.
### 
```
``[INFO]:    Building python2 for armeabi-v7a
[INFO]:    Copying hostpython binary to targetpython folder
[INFO]:    -> running cp /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/hostpython2/desktop/hostpython2/hostpython /home/kivy/Desktop/C...(and 80 more)
[INFO]:    Building numpy for armeabi-v7a
[INFO]:    numpy apparently isn't already in site-packages
[INFO]:    Building compiled components in numpy
[INFO]:    -> directory context /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy
[INFO]:    -> running python.host setup.py build_ext -v
           working:     raise RuntimeError("Broken toolchain: cannot link a simple C program")                                                                         Exception in thread background thread for pid 30572:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 2170, in background_thread
    handle_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1929, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
ErrorReturnCode_1: 

  RAN: /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/bin/python.host setup.py build_ext -v

  STDOUT:
Running from numpy source directory.
/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'test_suite'
  warnings.warn(msg)
non-existing path in 'numpy/distutils': 'site.cfg'
non-existing path in 'numpy/f2py': 'docs'
non-existing path in 'numpy/f2py': 'f2py.1'
/bin/sh: 1: svnversion: not found
F2PY Version 2
blas_opt_info:
blas_mkl_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

openblas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_3_10_blas_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_3_10_blas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_blas_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_blas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1604: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
blas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1613: UserWarning: 
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.
  warnings.warn(BlasNotFoundError.__doc__)
blas_src_info:
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1616: UserWarning: 
    Blas (http://www.netlib.org/blas/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [blas_src]) or by setting
    the BLAS_SRC environment variable.
  warnings.warn(BlasSrcNotFoundError.__doc__)
  NOT AVAILABLE

/bin/sh: 1: svnversion: not found
non-existing path in 'numpy/lib': 'benchmarks'
lapack_opt_info:
openblas_lapack_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

lapack_mkl_info:
mkl_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

  NOT AVAILABLE

atlas_3_10_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_3_10_threads_info
  NOT AVAILABLE

atlas_3_10_info:
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_3_10_info
  NOT AVAILABLE

atlas_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_threads_info
  NOT AVAILABLE

atlas_info:
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_info
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1506: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
lapack_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1517: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [lapack]) or by setting
    the LAPACK environment variable.
  warnings.warn(LapackNotFoundError.__doc__)
lapack_src_info:
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1520: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [lapack_src]) or by setting
    the LAPACK_SRC environment variable.
  warnings.warn(LapackSrcNotFoundError.__doc__)
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'define_macros'
  warnings.warn(msg)
running build_ext
running build_src
build_src
building py_modules sources
creating build
creating build/src.linux-x86_64-2.7
creating build/src.linux-x86_64-2.7/numpy
creating build/src.linux-x86_64-2.7/numpy/distutils
building library "npymath" sources
customize Gnu95FCompiler
Could not locate executable gfortran
Could not locate executable f95
customize IntelFCompiler
Could not locate executable ifort
Could not locate executable ifc
customize LaheyFCompiler
Could not locate executable lf95
customize PGroupFCompiler
Could not locate executable pgfortran
customize AbsoftFCompiler
Could not locate executable f90
Could not locate executable f77
customize NAGFCompiler
customize VastFCompiler
customize CompaqFCompiler
Could not locate executable fort
customize IntelItaniumFCompiler
Could not locate executable efort
Could not locate executable efc
customize IntelEM64TFCompiler
customize GnuFCompiler
Could not locate executable g77
customize G95FCompiler
Could not locate executable g95
customize PathScaleFCompiler
Could not locate executable pathf95
don't know how to compile Fortran code on platform 'posix'
C compiler: arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer -D__ANDROID_API__=19 -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -isysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DANDROID -mandroid -fomit-frame-pointer -D__ANDROID_API__=19 -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -isysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC

compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -c'
arm-linux-androideabi-gcc: _configtest.c
arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer -D__ANDROID_API__=19 -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -isysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 _configtest.o -o _configtest
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
failure.
removing: _configtest.c _configtest.o
Traceback (most recent call last):
  File "setup.py", line 251, in <module>
    setup_package()
  File "setup.py", line 243, in setup_package
    setup(**metadata)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/core.py", line 169, in setup
    return old_setup(**new_attr)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_ext.py", line 59, in run
    self.run_command('build_src')
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 153, in run
    self.build_sources()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 164, in build_sources
    self.build_library_sources(*libname_info)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 299, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 386, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program


  STDERR:


Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 978, in <module>
    main()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 975, in main
    ToolchainCL()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 512, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 149, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 193, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "pythonforandroid/build.py", line 573, in build_recipes
  File "pythonforandroid/recipe.py", line 843, in build_arch
  File "pythonforandroid/recipe.py", line 855, in build_compiled_components
  File "pythonforandroid/logger.py", line 175, in shprint
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 720, in next
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 651, in wait
    self.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/bin/python.host setup.py build_ext -v

  STDOUT:
Running from numpy source directory.
/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'test_suite'
  warnings.warn(msg)
non-existing path in 'numpy/distutils': 'site.cfg'
non-existing path in 'numpy/f2py': 'docs'
non-existing path in 'numpy/f2py': 'f2py.1'
/bin/sh: 1: svnversion: not found
F2PY Version 2
blas_opt_info:
blas_mkl_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

openblas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_3_10_blas_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_3_10_blas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_blas_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

atlas_blas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1604: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
blas_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1613: UserWarning: 
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.
  warnings.warn(BlasNotFoundError.__doc__)
blas_src_info:
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1616: UserWarning: 
    Blas (http://www.netlib.org/blas/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [blas_src]) or by setting
    the BLAS_SRC environment variable.
  warnings.warn(BlasSrcNotFoundError.__doc__)
  NOT AVAILABLE

/bin/sh: 1: svnversion: not found
non-existing path in 'numpy/lib': 'benchmarks'
lapack_opt_info:
openblas_lapack_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

lapack_mkl_info:
mkl_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

  NOT AVAILABLE

atlas_3_10_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_3_10_threads_info
  NOT AVAILABLE

atlas_3_10_info:
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_3_10_info
  NOT AVAILABLE

atlas_threads_info:
Setting PTATLAS=ATLAS
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_threads_info
  NOT AVAILABLE

atlas_info:
  libraries  not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries lapack_atlas not found in /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib
  libraries  not found in /usr/local/lib
  libraries lapack_atlas not found in /usr/local/lib
  libraries  not found in /usr/lib
  libraries lapack_atlas not found in /usr/lib
  libraries  not found in /usr/lib/x86_64-linux-gnu
  libraries lapack_atlas not found in /usr/lib/x86_64-linux-gnu
numpy.distutils.system_info.atlas_info
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1506: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
lapack_info:
  libraries  not found in ['/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib', '/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu']
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1517: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [lapack]) or by setting
    the LAPACK environment variable.
  warnings.warn(LapackNotFoundError.__doc__)
lapack_src_info:
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/system_info.py:1520: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [lapack_src]) or by setting
    the LAPACK_SRC environment variable.
  warnings.warn(LapackSrcNotFoundError.__doc__)
  NOT AVAILABLE

/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'define_macros'
  warnings.warn(msg)
running build_ext
running build_src
build_src
building py_modules sources
creating build
creating build/src.linux-x86_64-2.7
creating build/src.linux-x86_64-2.7/numpy
creating build/src.linux-x86_64-2.7/numpy/distutils
building library "npymath" sources
customize Gnu95FCompiler
Could not locate executable gfortran
Could not locate executable f95
customize IntelFCompiler
Could not locate executable ifort
Could not locate executable ifc
customize LaheyFCompiler
Could not locate executable lf95
customize PGroupFCompiler
Could not locate executable pgfortran
customize AbsoftFCompiler
Could not locate executable f90
Could not locate executable f77
customize NAGFCompiler
customize VastFCompiler
customize CompaqFCompiler
Could not locate executable fort
customize IntelItaniumFCompiler
Could not locate executable efort
Could not locate executable efc
customize IntelEM64TFCompiler
customize GnuFCompiler
Could not locate executable g77
customize G95FCompiler
Could not locate executable g95
customize PathScaleFCompiler
Could not locate executable pathf95
don't know how to compile Fortran code on platform 'posix'
C compiler: arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer -D__ANDROID_API__=19 -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -isysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DANDROID -mandroid -fomit-frame-pointer -D__ANDROID_API__=19 -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -isysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC

compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -c'
arm-linux-androideabi-gcc: _configtest.c
arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer -D__ANDROID_API__=19 -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -isysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -I/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 _configtest.o -o _configtest
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
failure.
removing: _configtest.c _configtest.o
Traceback (most recent call last):
  File "setup.py", line 251, in <module>
    setup_package()
  File "setup.py", line 243, in setup_package
    setup(**metadata)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/core.py", line 169, in setup
    return old_setup(**new_attr)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_ext.py", line 59, in run
    self.run_command('build_src')
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 153, in run
    self.build_sources()
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 164, in build_sources
    self.build_library_sources(*libname_info)
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 299, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/numpy/armeabi-v7a/numpy/numpy/distutils/command/build_src.py", line 386, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program



```
I installed openCV using pip, but broken toolchain error persists
I am getting this issue even with python2 for numpy and openCV
Yes I think I saw the numpy error when I tried to reproduce your issue with opencv. I could compile opencv without issue, however yes if I recall correctly I think I saw numpy crashed.
The funny thing is numpy is part of the integration testing https://github.com/kivy/python-for-android/pull/1304/files
So it would be interesting to see how it differs from your local installation.
Edit: Also I saw a lot of numpy related tickets already, can you check if you find one that matches your issue? I think there's a branch that fix some numpy issues, but broke it for crystax so it the pull request was reverted, but the branch is still here.
I cloned the p4abranch:
git clone git://github.com/kivy/python-for-android
and changed the p4a source directory in spec file to this, it resolved the numpy error for me, but an error still persists with openCV regarding CMake ( I have raised another issue for that.)

Resolving patch:
diff --git a/ci/constants.py b/ci/constants.py
--- a/ci/constants.py
+++ b/ci/constants.py
@@ -82,8 +82,6 @@ class TargetPython(Enum):
     # requires `libpq-dev` system dependency e.g. for `pg_config` binary
     'psycopg2',
     'netifaces',
-    # https://github.com/kivy/python-for-android/issues/1315 ?
-    'opencv',
     'protobuf_cpp',
     # most likely some setup in the Docker container, because it works in host
     'pyjnius', 'pyopenal',
diff --git a/pythonforandroid/recipes/opencv/__init__.py b/pythonforandroid/recipes/opencv/__init__.py
--- a/pythonforandroid/recipes/opencv/__init__.py
+++ b/pythonforandroid/recipes/opencv/__init__.py
@@ -9,45 +9,43 @@
 
 
 class OpenCVRecipe(NDKRecipe):
-    version = '2.4.10.1'
-    url = 'https://github.com/Itseez/opencv/archive/{version}.zip'
-    # md5sum = '2ddfa98e867e6611254040df841186dc'
+    version = '4.0.1'
+    url = 'https://github.com/opencv/opencv/archive/{version}.zip'
     depends = ['numpy']
-    patches = ['patches/p4a_build-2.4.10.1.patch']
-    generated_libraries = ['cv2.so']
-
-    def prebuild_arch(self, arch):
-        self.apply_patches(arch)
 
     def get_recipe_env(self, arch):
         env = super(OpenCVRecipe, self).get_recipe_env(arch)
-        env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
         env['ANDROID_NDK'] = self.ctx.ndk_dir
         env['ANDROID_SDK'] = self.ctx.sdk_dir
-        env['SITEPACKAGES_PATH'] = self.ctx.get_site_packages_dir()
         return env
 
+    def should_build(self, arch):
+        return True
+
     def build_arch(self, arch):
-        with current_directory(self.get_build_dir(arch.arch)):
+        build_dir = os.path.join(self.get_build_dir(arch.arch), 'build')
+        shprint(sh.mkdir, '-p', build_dir)
+        with current_directory(build_dir):
             env = self.get_recipe_env(arch)
-            cvsrc = self.get_build_dir(arch.arch)
-            lib_dir = os.path.join(self.ctx.get_python_install_dir(), "lib")
-
             shprint(sh.cmake,
-                    '-DP4A=ON', '-DANDROID_ABI={}'.format(arch.arch),
-                    '-DCMAKE_TOOLCHAIN_FILE={}/platforms/android/android.toolchain.cmake'.format(cvsrc),
-                    '-DPYTHON_INCLUDE_PATH={}/include/python2.7'.format(env['PYTHON_ROOT']),
-                    '-DPYTHON_LIBRARY={}/lib/libpython2.7.so'.format(env['PYTHON_ROOT']),
-                    '-DPYTHON_NUMPY_INCLUDE_DIR={}/numpy/core/include'.format(env['SITEPACKAGES_PATH']),
+                    '-DANDROID_ABI={}'.format(arch.arch),
+                    '-DCMAKE_TOOLCHAIN_FILE={}/build/cmake/android.toolchain.cmake'.format(self.ctx.ndk_dir),
+                    '-DPYTHON_NUMPY_INCLUDE_DIR={}/numpy/core/include'.format(self.ctx.get_site_packages_dir()),
                     '-DANDROID_EXECUTABLE={}/tools/android'.format(env['ANDROID_SDK']),
-                    '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF',
+                    '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF', '-DENABLE_TESTING=OFF',
                     '-DBUILD_EXAMPLES=OFF', '-DBUILD_ANDROID_EXAMPLES=OFF',
-                    '-DPYTHON_PACKAGES_PATH={}'.format(env['SITEPACKAGES_PATH']),
-                    cvsrc,
+                    '-DBUILD_opencv_imgproc=OFF', '-DBUILD_opencv_flann=OFF',
+                    '-DBUILD_opencv_python3=ON',
+                    '-DBUILD_WITH_STANDALONE_TOOLCHAIN=ON',
+                    '-DPYTHON_PACKAGES_PATH={}'.format(self.ctx.get_site_packages_dir()),
+                    '-DANDROID_STANDALONE_TOOLCHAIN={}'.format(self.ctx.ndk_dir),
+                    '-DANDROID_NATIVE_API_LEVEL={}'.format(self.ctx.android_api),
+                    self.get_build_dir(arch.arch),
                     _env=env)
-            shprint(sh.make, '-j', str(cpu_count()), 'opencv_python')
+            shprint(sh.make, '-j', str(cpu_count()))
             shprint(sh.cmake, '-DCOMPONENT=python', '-P', './cmake_install.cmake')
-            sh.cp('-a', sh.glob('./lib/{}/lib*.so'.format(arch.arch)), lib_dir)
+            sh.cp('-a', sh.glob('./lib/{}/lib*.a'.format(arch.arch)), self.ctx.get_libs_dir(arch.arch))
+            self.ctx.get_libs_dir(arch.arch)
 
 
 recipe = OpenCVRecipe()


Test patch: