Repository: kivy/python-for-android

Issue:
ctypes.util.find_library() doesn't work on arch arm64-v8a
<!--
The issue tracker is a tool to address bugs.
Please use the Disord community or Stack Overflow for support questions,
more information at https://github.com/kivy/python-for-android#support

Before opening a new issue, make sure you do the following:
    * check that your issue isn't already filed: https://github.com/kivy/python-for-android/issues
    * prepare a short, runnable example that reproduces the issue
    * make sure to have `log_level = 2` in your `buildozer.spec`
    * reproduce the problem with the latest development version (`p4a.branch = master`)
    * double-check that the issue is indeed a bug and not a support request
    * please use backticks to format code or logs
-->

### Versions

* Python: 3.6.7
* OS: Ubuntu 18.10
* Kivy: N/A
* Cython: 0.29.6

### Description

Build for arch `arm64-v8a` succeeds but raises a `FileNotFoundError` during execution *(see logcat below)*

According to @inclement, this might be related to  #1701 

### buildozer.spec

*Not using buildozer.*

**setup.py**
```python
from distutils.core import setup
from setuptools import find_packages


options = {'apk': {'debug': None,
                   'bootstrap': 'sdl2',
                   'requirements': 'libffi,sdl2,sdl2_image,python3,pysdl2,Pillow',
                   'package': 'org.some.put',
                   'android-api': 28,
                   'arch': 'arm64-v8a',
                   'dist-name': 'bdisttest',
                   }}

setup(
    name='foo',
    version='0.1',
    description='bar',
    author='me',
    author_email='foo@bar.com',
    packages=find_packages(),
    options=options,
    package_data={'foobar': ['*.py', 'gui/*.py', 'assets/images/*.png']}
)
```

### Logs

**adb logcat | grep python**
```
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libpython3.7m.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libssl1.1.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2_mixer.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2_ttf.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libffi.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libmain.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libhidapi.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libsqlite3.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libcrypto1.1.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2_image.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libpython3.7m.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libssl1.1.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_mixer.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_ttf.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libffi.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libmain.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libhidapi.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libsqlite3.so
03-24 20:29:10.694  2554  2554 V pythonutil: Pattern libsqlite3\.so matched file libsqlite3.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libcrypto1.1.so
03-24 20:29:10.695  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_image.so
03-24 20:29:10.695  2554  2554 V pythonutil: Checking pattern libffi\.so against libpython3.7m.so
03-24 20:29:10.695  2554  2554 V pythonutil: Checking pattern libffi\.so against libssl1.1.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2_mixer.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2_ttf.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libffi.so
03-24 20:29:10.696  2554  2554 V pythonutil: Pattern libffi\.so matched file libffi.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libmain.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libhidapi.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libsqlite3.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libcrypto1.1.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2_image.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libpython3.7m.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libssl1.1.so
03-24 20:29:10.697  2554  2554 V pythonutil: Pattern libssl.*\.so matched file libssl1.1.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2_mixer.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2_ttf.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libffi.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libmain.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libhidapi.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libsqlite3.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libcrypto1.1.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2_image.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libpython3.7m.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libssl1.1.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_mixer.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_ttf.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libffi.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libmain.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libhidapi.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libsqlite3.so
03-24 20:29:10.700  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libcrypto1.1.so
03-24 20:29:10.700  2554  2554 V pythonutil: Pattern libcrypto.*\.so matched file libcrypto1.1.so
03-24 20:29:10.700  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_image.so
03-24 20:29:10.700  2554  2554 V pythonutil: Loading library: sqlite3
03-24 20:29:10.702  2554  2554 V pythonutil: Loading library: ffi
03-24 20:29:10.703  2554  2554 V pythonutil: Loading library: SDL2
03-24 20:29:10.706  2554  2554 V pythonutil: Loading library: SDL2_image
03-24 20:29:10.708  2554  2554 V pythonutil: Loading library: SDL2_mixer
03-24 20:29:10.710  2554  2554 V pythonutil: Loading library: SDL2_ttf
03-24 20:29:10.712  2554  2554 V pythonutil: Loading library: ssl1.1
03-24 20:29:10.714  2554  2554 V pythonutil: Loading library: crypto1.1
03-24 20:29:10.715  2554  2554 V pythonutil: Loading library: python2.7
03-24 20:29:10.716  2554  2554 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/lib/arm64, /data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libpython2.7.so"
03-24 20:29:10.717  2554  2554 V pythonutil: Loading library: python3.5m
03-24 20:29:10.717  2554  2554 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/lib/arm64, /data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libpython3.5m.so"
03-24 20:29:10.717  2554  2554 V pythonutil: Loading library: python3.6m
03-24 20:29:10.718  2554  2554 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/lib/arm64, /data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libpython3.6m.so"
03-24 20:29:10.718  2554  2554 V pythonutil: Loading library: python3.7m
03-24 20:29:10.721  2554  2554 V pythonutil: Loading library: main
03-24 20:29:10.722  2554  2554 V pythonutil: Failed to load _io.so or unicodedata.so...but that's okay.
03-24 20:29:10.723  2554  2554 V pythonutil: Unsatisfied linker when loading ctypes
03-24 20:29:10.723  2554  2554 V pythonutil: Loaded everything!
03-24 20:29:10.810  2554  2588 I python  : Initializing Python for Android
03-24 20:29:10.810  2554  2588 I python  : Setting additional env vars from p4a_env_vars.txt
03-24 20:29:10.810  2554  2588 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
03-24 20:29:10.810  2554  2588 I python  : /data/user/0/com.tizilogic.pyos/files/app
03-24 20:29:10.811  2554  2588 I python  : Preparing to initialize python
03-24 20:29:10.811  2554  2588 I python  : _python_bundle dir exists
03-24 20:29:10.811  2554  2588 I python  : calculated paths to be...
03-24 20:29:10.811  2554  2588 I python  : /data/user/0/com.tizilogic.pyos/files/app/_python_bundle/stdlib.zip:/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/modules
03-24 20:29:10.811  2554  2588 I python  : set wchar paths...
03-24 20:29:10.849  2554  2588 I python  : Initialized python
03-24 20:29:10.849  2554  2588 I python  : AND: Init threads
03-24 20:29:10.849  2554  2588 I python  : testing python print redirection
03-24 20:29:10.850  2554  2588 I python  : Android path ['.', '/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/stdlib.zip', '/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/modules', '/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/site-packages']
03-24 20:29:10.851  2554  2588 I python  : os.environ is environ({'PATH': '/sbin:/system/sbin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin', 'DOWNLOAD_CACHE': '/data/cache', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/legacy-test.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/smartbondingservice.jar:/system/framework/sprengine.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/timakeystore.jar:/system/framework/fipstimakeystore.jar:/system/framework/ucmopensslenginehelper.jar:/system/framework/esecomm.jar:/system/framework/SemAudioThumbnail.jar:/system/framework/knoxsdk.jar:/system/framework/sec_edm.jar:/system/framework/sagearpolicymanager.jar:/system/framework/sec_sdp_sdk.jar:/system/framework/sec_sdp_hidden_sdk.jar:/system/framework/knoxvpnuidtag.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/samsung-services.jar:/system/framework/hqm.jar:/system/framework/dmf.jar:/system/framework/ssrm.jar', 'MC_AUTH_TOKEN_PATH': '/efs', 'KNOX_STORAGE': '/data/knox/ext_sdcard', 'ENC_EMULATED_STORAGE_TARGET': '/storage/enc_emulated', 'ANDROID_SOCKET_zygote': '8', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/com.tizilogic.pyos/files/app', 'ANDROID_APP_PATH': '/data/user/0/com.tizilogic.pyos/files/app', 'ANDROID_PRIVATE': '/data/user/0/com.tizilogic.pyos/files', 'ANDROID_UNPACK': '/data/user/0/com.tizilogic.pyos/files/app', 'PYTHONHOME': '/data/user/0/com.tizilogic.pyos/files/app', 'PYTHONPATH': '/data/user/0/com.tizilogic.pyos/files/app:/data/user/0/com.tizilogic.pyos/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'False', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
03-24 20:29:10.851  2554  2588 I python  : Android kivy bootstrap done. __name__ is __main__
03-24 20:29:10.851  2554  2588 I python  : AND: Ran string
03-24 20:29:10.851  2554  2588 I python  : Run user program, change dir and execute entrypoint
03-24 20:29:10.985  2554  2588 I python  : Traceback (most recent call last):
03-24 20:29:10.985  2554  2588 I python  :   File "/home/userhome/workspace/build/bdist.android-arm64-v8a/pyos/main.py", line 6, in <module>
03-24 20:29:10.985  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/__init__.py", line 2, in <module>
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/dll.py", line 111, in <module>
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/dll.py", line 49, in __init__
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/dll.py", line 37, in _findlib
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/other_builds/python3-libffi-openssl-sqlite3/arm64-v8a__ndk_target_21/python3/Lib/ctypes/util.py", line 78, in find_library
03-24 20:29:10.986  2554  2588 I python  : FileNotFoundError: [Errno 2] No such file or directory: '/data/data/com.tizilogic.pyos/lib'
03-24 20:29:10.986  2554  2588 I python  : Python for android ended.
```

ctypes.util.find_library() doesn't work on arch arm64-v8a
<!--
The issue tracker is a tool to address bugs.
Please use the Disord community or Stack Overflow for support questions,
more information at https://github.com/kivy/python-for-android#support

Before opening a new issue, make sure you do the following:
    * check that your issue isn't already filed: https://github.com/kivy/python-for-android/issues
    * prepare a short, runnable example that reproduces the issue
    * make sure to have `log_level = 2` in your `buildozer.spec`
    * reproduce the problem with the latest development version (`p4a.branch = master`)
    * double-check that the issue is indeed a bug and not a support request
    * please use backticks to format code or logs
-->

### Versions

* Python: 3.6.7
* OS: Ubuntu 18.10
* Kivy: N/A
* Cython: 0.29.6

### Description

Build for arch `arm64-v8a` succeeds but raises a `FileNotFoundError` during execution *(see logcat below)*

According to @inclement, this might be related to  #1701 

### buildozer.spec

*Not using buildozer.*

**setup.py**
```python
from distutils.core import setup
from setuptools import find_packages


options = {'apk': {'debug': None,
                   'bootstrap': 'sdl2',
                   'requirements': 'libffi,sdl2,sdl2_image,python3,pysdl2,Pillow',
                   'package': 'org.some.put',
                   'android-api': 28,
                   'arch': 'arm64-v8a',
                   'dist-name': 'bdisttest',
                   }}

setup(
    name='foo',
    version='0.1',
    description='bar',
    author='me',
    author_email='foo@bar.com',
    packages=find_packages(),
    options=options,
    package_data={'foobar': ['*.py', 'gui/*.py', 'assets/images/*.png']}
)
```

### Logs

**adb logcat | grep python**
```
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libpython3.7m.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libssl1.1.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2_mixer.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2_ttf.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libffi.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libmain.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2.so
03-24 20:29:10.692  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libhidapi.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libsqlite3.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libcrypto1.1.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libcrystax\.so against libSDL2_image.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libpython3.7m.so
03-24 20:29:10.693  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libssl1.1.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_mixer.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_ttf.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libffi.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libmain.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libhidapi.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libsqlite3.so
03-24 20:29:10.694  2554  2554 V pythonutil: Pattern libsqlite3\.so matched file libsqlite3.so
03-24 20:29:10.694  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libcrypto1.1.so
03-24 20:29:10.695  2554  2554 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_image.so
03-24 20:29:10.695  2554  2554 V pythonutil: Checking pattern libffi\.so against libpython3.7m.so
03-24 20:29:10.695  2554  2554 V pythonutil: Checking pattern libffi\.so against libssl1.1.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2_mixer.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2_ttf.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libffi.so
03-24 20:29:10.696  2554  2554 V pythonutil: Pattern libffi\.so matched file libffi.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libmain.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libhidapi.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libsqlite3.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libcrypto1.1.so
03-24 20:29:10.696  2554  2554 V pythonutil: Checking pattern libffi\.so against libSDL2_image.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libpython3.7m.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libssl1.1.so
03-24 20:29:10.697  2554  2554 V pythonutil: Pattern libssl.*\.so matched file libssl1.1.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2_mixer.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2_ttf.so
03-24 20:29:10.697  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libffi.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libmain.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libhidapi.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libsqlite3.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libcrypto1.1.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libssl.*\.so against libSDL2_image.so
03-24 20:29:10.698  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libpython3.7m.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libssl1.1.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_mixer.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_ttf.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libffi.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libmain.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libhidapi.so
03-24 20:29:10.699  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libsqlite3.so
03-24 20:29:10.700  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libcrypto1.1.so
03-24 20:29:10.700  2554  2554 V pythonutil: Pattern libcrypto.*\.so matched file libcrypto1.1.so
03-24 20:29:10.700  2554  2554 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_image.so
03-24 20:29:10.700  2554  2554 V pythonutil: Loading library: sqlite3
03-24 20:29:10.702  2554  2554 V pythonutil: Loading library: ffi
03-24 20:29:10.703  2554  2554 V pythonutil: Loading library: SDL2
03-24 20:29:10.706  2554  2554 V pythonutil: Loading library: SDL2_image
03-24 20:29:10.708  2554  2554 V pythonutil: Loading library: SDL2_mixer
03-24 20:29:10.710  2554  2554 V pythonutil: Loading library: SDL2_ttf
03-24 20:29:10.712  2554  2554 V pythonutil: Loading library: ssl1.1
03-24 20:29:10.714  2554  2554 V pythonutil: Loading library: crypto1.1
03-24 20:29:10.715  2554  2554 V pythonutil: Loading library: python2.7
03-24 20:29:10.716  2554  2554 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/lib/arm64, /data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libpython2.7.so"
03-24 20:29:10.717  2554  2554 V pythonutil: Loading library: python3.5m
03-24 20:29:10.717  2554  2554 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/lib/arm64, /data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libpython3.5m.so"
03-24 20:29:10.717  2554  2554 V pythonutil: Loading library: python3.6m
03-24 20:29:10.718  2554  2554 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/lib/arm64, /data/app/com.tizilogic.pyos-UUr8o1SWqdGHXQVCTO8uLQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libpython3.6m.so"
03-24 20:29:10.718  2554  2554 V pythonutil: Loading library: python3.7m
03-24 20:29:10.721  2554  2554 V pythonutil: Loading library: main
03-24 20:29:10.722  2554  2554 V pythonutil: Failed to load _io.so or unicodedata.so...but that's okay.
03-24 20:29:10.723  2554  2554 V pythonutil: Unsatisfied linker when loading ctypes
03-24 20:29:10.723  2554  2554 V pythonutil: Loaded everything!
03-24 20:29:10.810  2554  2588 I python  : Initializing Python for Android
03-24 20:29:10.810  2554  2588 I python  : Setting additional env vars from p4a_env_vars.txt
03-24 20:29:10.810  2554  2588 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
03-24 20:29:10.810  2554  2588 I python  : /data/user/0/com.tizilogic.pyos/files/app
03-24 20:29:10.811  2554  2588 I python  : Preparing to initialize python
03-24 20:29:10.811  2554  2588 I python  : _python_bundle dir exists
03-24 20:29:10.811  2554  2588 I python  : calculated paths to be...
03-24 20:29:10.811  2554  2588 I python  : /data/user/0/com.tizilogic.pyos/files/app/_python_bundle/stdlib.zip:/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/modules
03-24 20:29:10.811  2554  2588 I python  : set wchar paths...
03-24 20:29:10.849  2554  2588 I python  : Initialized python
03-24 20:29:10.849  2554  2588 I python  : AND: Init threads
03-24 20:29:10.849  2554  2588 I python  : testing python print redirection
03-24 20:29:10.850  2554  2588 I python  : Android path ['.', '/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/stdlib.zip', '/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/modules', '/data/user/0/com.tizilogic.pyos/files/app/_python_bundle/site-packages']
03-24 20:29:10.851  2554  2588 I python  : os.environ is environ({'PATH': '/sbin:/system/sbin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin', 'DOWNLOAD_CACHE': '/data/cache', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/legacy-test.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/smartbondingservice.jar:/system/framework/sprengine.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/timakeystore.jar:/system/framework/fipstimakeystore.jar:/system/framework/ucmopensslenginehelper.jar:/system/framework/esecomm.jar:/system/framework/SemAudioThumbnail.jar:/system/framework/knoxsdk.jar:/system/framework/sec_edm.jar:/system/framework/sagearpolicymanager.jar:/system/framework/sec_sdp_sdk.jar:/system/framework/sec_sdp_hidden_sdk.jar:/system/framework/knoxvpnuidtag.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/samsung-services.jar:/system/framework/hqm.jar:/system/framework/dmf.jar:/system/framework/ssrm.jar', 'MC_AUTH_TOKEN_PATH': '/efs', 'KNOX_STORAGE': '/data/knox/ext_sdcard', 'ENC_EMULATED_STORAGE_TARGET': '/storage/enc_emulated', 'ANDROID_SOCKET_zygote': '8', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/com.tizilogic.pyos/files/app', 'ANDROID_APP_PATH': '/data/user/0/com.tizilogic.pyos/files/app', 'ANDROID_PRIVATE': '/data/user/0/com.tizilogic.pyos/files', 'ANDROID_UNPACK': '/data/user/0/com.tizilogic.pyos/files/app', 'PYTHONHOME': '/data/user/0/com.tizilogic.pyos/files/app', 'PYTHONPATH': '/data/user/0/com.tizilogic.pyos/files/app:/data/user/0/com.tizilogic.pyos/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'False', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
03-24 20:29:10.851  2554  2588 I python  : Android kivy bootstrap done. __name__ is __main__
03-24 20:29:10.851  2554  2588 I python  : AND: Ran string
03-24 20:29:10.851  2554  2588 I python  : Run user program, change dir and execute entrypoint
03-24 20:29:10.985  2554  2588 I python  : Traceback (most recent call last):
03-24 20:29:10.985  2554  2588 I python  :   File "/home/userhome/workspace/build/bdist.android-arm64-v8a/pyos/main.py", line 6, in <module>
03-24 20:29:10.985  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/__init__.py", line 2, in <module>
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/dll.py", line 111, in <module>
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/dll.py", line 49, in __init__
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/python-installs/bdisttest/sdl2/dll.py", line 37, in _findlib
03-24 20:29:10.986  2554  2588 I python  :   File "/home/userhome/.local/share/python-for-android/build/other_builds/python3-libffi-openssl-sqlite3/arm64-v8a__ndk_target_21/python3/Lib/ctypes/util.py", line 78, in find_library
03-24 20:29:10.986  2554  2588 I python  : FileNotFoundError: [Errno 2] No such file or directory: '/data/data/com.tizilogic.pyos/lib'
03-24 20:29:10.986  2554  2588 I python  : Python for android ended.
```



Discussion:
Could you share your `pip freeze` please? The idea is to know at least the `python-for-android` version you're running
happy to:
```
appdirs==1.4.3  
asn1crypto==0.24.0
buildozer==0.39
colorama==0.4.1
cryptography==2.1.4
Cython==0.29.6
idna==2.6
Jinja2==2.10
keyring==10.6.0
keyrings.alt==3.0
MarkupSafe==1.1.1
pexpect==4.6.0
ptyprocess==0.6.0
pycrypto==2.6.1
pygobject==3.26.1
python-for-android==0.7.1
pyxdg==0.25
SecretStorage==2.3.1
sh==1.12.14
six==1.11.0
virtualenv==15.1.0
```
@tcdude can you send the .apk to `jonas@thiem.email`? (I promise to keep it confidential/only use it to examine this issue) If I can install it on my local device and see where things end up then I should hopefully be able to figure out what the problem is pretty quick
@JonasT I sent a link to the indicated address. Hope it helps, let me know if I can provide more detail/information.
@tcdude thanks, got it, and I can see what the issue is. we are affected by this: https://stackoverflow.com/questions/41709129/lib-directory-missing-after-installing-64-bit-android-application

I'm preparing a fix
Could you share your `pip freeze` please? The idea is to know at least the `python-for-android` version you're running
happy to:
```
appdirs==1.4.3  
asn1crypto==0.24.0
buildozer==0.39
colorama==0.4.1
cryptography==2.1.4
Cython==0.29.6
idna==2.6
Jinja2==2.10
keyring==10.6.0
keyrings.alt==3.0
MarkupSafe==1.1.1
pexpect==4.6.0
ptyprocess==0.6.0
pycrypto==2.6.1
pygobject==3.26.1
python-for-android==0.7.1
pyxdg==0.25
SecretStorage==2.3.1
sh==1.12.14
six==1.11.0
virtualenv==15.1.0
```
@tcdude can you send the .apk to `jonas@thiem.email`? (I promise to keep it confidential/only use it to examine this issue) If I can install it on my local device and see where things end up then I should hopefully be able to figure out what the problem is pretty quick
@JonasT I sent a link to the indicated address. Hope it helps, let me know if I can provide more detail/information.
@tcdude thanks, got it, and I can see what the issue is. we are affected by this: https://stackoverflow.com/questions/41709129/lib-directory-missing-after-installing-64-bit-android-application

I'm preparing a fix

Resolving patch:
diff --git a/pythonforandroid/recipes/android/src/android/_ctypes_library_finder.py b/pythonforandroid/recipes/android/src/android/_ctypes_library_finder.py
new file mode 100644
--- /dev/null
+++ b/pythonforandroid/recipes/android/src/android/_ctypes_library_finder.py
@@ -0,0 +1,63 @@
+
+import os
+
+
+def get_activity_lib_dir(activity_name):
+    from jnius import autoclass
+
+    # Get the actual activity instance:
+    activity_class = autoclass(activity_name)
+    if activity_class is None:
+        return None
+    activity = None
+    if hasattr(activity_class, "mActivity") and \
+            activity_class.mActivity is not None:
+        activity = activity_class.mActivity
+    elif hasattr(activity_class, "mService") and \
+            activity_class.mService is not None:
+        activity = activity_class.mService
+    if activity is None:
+        return None
+
+    # Extract the native lib dir from the activity instance:
+    package_name = activity.getApplicationContext().getPackageName()
+    manager = activity.getApplicationContext().getPackageManager()
+    manager_class = autoclass("android.content.pm.PackageManager")
+    native_lib_dir = manager.getApplicationInfo(
+        package_name, manager_class.GET_SHARED_LIBRARY_FILES
+    ).nativeLibraryDir
+    return native_lib_dir
+
+
+def does_libname_match_filename(search_name, file_path):
+    # Filter file names so given search_name="mymodule" we match one of:
+    #      mymodule.so         (direct name + .so)
+    #      libmymodule.so      (added lib prefix)
+    #      mymodule.arm64.so   (added dot-separated middle parts)
+    #      mymodule.so.1.3.4   (added dot-separated version tail)
+    #      and all above       (all possible combinations)
+    import re
+    file_name = os.path.basename(file_path)
+    return (re.match(r"^(lib)?" + re.escape(search_name) +
+                     r"\.(.*\.)?so(\.[0-9]+)*$", file_name) is not None)
+
+
+def find_library(name):
+    # Obtain all places for native libraries:
+    lib_search_dirs = ["/system/lib"]
+    lib_dir_1 = get_activity_lib_dir("org.kivy.android.PythonActivity")
+    if lib_dir_1 is not None:
+        lib_search_dirs.insert(0, lib_dir_1)
+    lib_dir_2 = get_activity_lib_dir("org.kivy.android.PythonService")
+    if lib_dir_2 is not None and lib_dir_2 not in lib_search_dirs:
+        lib_search_dirs.insert(0, lib_dir_2)
+
+    # Now scan the lib dirs:
+    for lib_dir in [l for l in lib_search_dirs if os.path.exists(l)]:
+        filelist = [
+            f for f in os.listdir(lib_dir)
+            if does_libname_match_filename(name, f)
+        ]
+        if len(filelist) > 0:
+            return os.path.join(lib_dir, filelist[0])
+    return None


Test patch:
diff --git a/tests/test_androidmodule_ctypes_finder.py b/tests/test_androidmodule_ctypes_finder.py
new file mode 100644
--- /dev/null
+++ b/tests/test_androidmodule_ctypes_finder.py
@@ -0,0 +1,124 @@
+
+import mock
+from mock import MagicMock
+import os
+import shutil
+import sys
+import tempfile
+
+
+# Import the tested android._ctypes_library_finder module,
+# making sure android._android won't crash us!
+# (since android._android is android-only / not compilable on desktop)
+android_module_folder = os.path.abspath(os.path.join(
+    os.path.dirname(__file__),
+    "..", "pythonforandroid", "recipes", "android", "src"
+))
+sys.path.insert(0, android_module_folder)
+sys.modules['android._android'] = MagicMock()
+import android._ctypes_library_finder
+sys.path.remove(android_module_folder)
+
+
+@mock.patch.dict('sys.modules', jnius=MagicMock())
+def test_get_activity_lib_dir():
+    import jnius  # should get us our fake module
+
+    # Short test that it works when activity doesn't exist:
+    jnius.autoclass = MagicMock()
+    jnius.autoclass.return_value = None
+    assert android._ctypes_library_finder.get_activity_lib_dir(
+        "JavaClass"
+    ) is None
+    assert mock.call("JavaClass") in jnius.autoclass.call_args_list
+
+    # Comprehensive test that verifies getApplicationInfo() call:
+    activity = MagicMock()
+    app_context = activity.getApplicationContext()
+    app_context.getPackageName.return_value = "test.package"
+    app_info = app_context.getPackageManager().getApplicationInfo()
+    app_info.nativeLibraryDir = '/testpath'
+
+    def pick_class(name):
+        cls = MagicMock()
+        if name == "JavaClass":
+            cls.mActivity = activity
+        elif name == "android.content.pm.PackageManager":
+            # Manager class:
+            cls.GET_SHARED_LIBRARY_FILES = 1024
+        return cls
+
+    jnius.autoclass = MagicMock(side_effect=pick_class)
+    assert android._ctypes_library_finder.get_activity_lib_dir(
+        "JavaClass"
+    ) == "/testpath"
+    assert mock.call("JavaClass") in jnius.autoclass.call_args_list
+    assert mock.call("test.package", 1024) in (
+        app_context.getPackageManager().getApplicationInfo.call_args_list
+    )
+
+
+@mock.patch.dict('sys.modules', jnius=MagicMock())
+def test_find_library():
+    test_d = tempfile.mkdtemp(prefix="p4a-android-ctypes-test-libdir-")
+    try:
+        with open(os.path.join(test_d, "mymadeuplib.so.5"), "w"):
+            pass
+        import jnius  # should get us our fake module
+
+        # Test with mActivity returned:
+        jnius.autoclass = MagicMock()
+        jnius.autoclass().mService = None
+        app_context = jnius.autoclass().mActivity.getApplicationContext()
+        app_info = app_context.getPackageManager().getApplicationInfo()
+        app_info.nativeLibraryDir = '/doesnt-exist-testpath'
+        assert android._ctypes_library_finder.find_library(
+            "mymadeuplib"
+        ) is None
+        assert mock.call("org.kivy.android.PythonActivity") in (
+            jnius.autoclass.call_args_list
+        )
+        app_info.nativeLibraryDir = test_d
+        assert os.path.normpath(android._ctypes_library_finder.find_library(
+            "mymadeuplib"
+        )) == os.path.normpath(os.path.join(test_d, "mymadeuplib.so.5"))
+
+        # Test with mService returned:
+        jnius.autoclass = MagicMock()
+        jnius.autoclass().mActivity = None
+        app_context = jnius.autoclass().mService.getApplicationContext()
+        app_info = app_context.getPackageManager().getApplicationInfo()
+        app_info.nativeLibraryDir = '/doesnt-exist-testpath'
+        assert android._ctypes_library_finder.find_library(
+            "mymadeuplib"
+        ) is None
+        app_info.nativeLibraryDir = test_d
+        assert os.path.normpath(android._ctypes_library_finder.find_library(
+            "mymadeuplib"
+        )) == os.path.normpath(os.path.join(test_d, "mymadeuplib.so.5"))
+    finally:
+        shutil.rmtree(test_d)
+
+
+def test_does_libname_match_filename():
+    assert android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "mylib.so"
+    )
+    assert not android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "amylib.so"
+    )
+    assert not android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "mylib.txt"
+    )
+    assert not android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "mylib"
+    )
+    assert android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "libmylib.test.so.1.2.3"
+    )
+    assert not android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "libtest.mylib.so"
+    )
+    assert android._ctypes_library_finder.does_libname_match_filename(
+        "mylib", "mylib.so.5"
+    )