kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.33k stars 1.84k forks source link

Webview apps not working on Android #1644

Closed inclement closed 2 years ago

inclement commented 5 years ago

Just tried the flask testapp with python2 and python3. Python 2 fails loading libpython2.7.so in werkzeug, while Python 3 fails at Py_Initialize in start.c.

Python 2:

01-31 20:27:37.704 20925 20967 I python  : [GCC 4.2.1 Compatible Android (4691093 based on r316199) Clang 6.0.2 (https://a
01-31 20:27:37.704 20925 20967 I python  : ('python path is', ['/data/data/org.test.testapp_flask2/files/app', '/data/user/0/org.test.testapp_flask2/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.testapp_flask2/files/app/_python_bundle/modules', '/data/user/0/org.test.testapp_flask2/files/app/_python_bundle/site-packages'])
01-31 20:27:37.704 20925 20967 I python  : imported os
01-31 20:27:37.710 20925 20967 I python  : Traceback (most recent call last):
01-31 20:27:37.710 20925 20967 I python  :   File "/home/sandy/devel/python-for-android/testapps/build/bdist.android-armeabi-v7a/testapp_flask/main.py", line 11, in <module>
01-31 20:27:37.710 20925 20967 I python  :   File "/home/sandy/.local/share/python-for-android/build/python-installs/testapp_flask/flask/__init__.py", line 17, in <module>
01-31 20:27:37.710 20925 20967 I python  :   File "/home/sandy/.local/share/python-for-android/build/python-installs/testapp_flask/werkzeug/__init__.py", line 20, in <module>
01-31 20:27:37.710 20925 20967 I python  :   File "/home/sandy/.local/share/python-for-android/build/python-installs/testapp_flask/werkzeug/_compat.py", line 5, in <module>
01-31 20:27:37.710 20925 20967 I python  : ImportError: dlopen failed: library "libpython2.7.so" not found
01-31 20:27:37.711 20925 20967 I python  : Python for android ended.

Python 3:

01-31 20:28:13.240 21005 21047 I python  : Initializing Python for Android
01-31 20:28:13.240 21005 21047 I python  : Setting additional env vars from p4a_env_vars.txt
01-31 20:28:13.240 21005 21047 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
01-31 20:28:13.240 21005 21047 I python  : /data/user/0/org.test.testapp_flask/files/app
01-31 20:28:13.241 21005 21047 I python  : Preparing to initialize python
01-31 20:28:13.241 21005 21047 I python  : _python_bundle dir exists
01-31 20:28:13.241 21005 21047 I python  : calculated paths to be...
01-31 20:28:13.241 21005 21047 I python  : /data/user/0/org.test.testapp_flask/files/app/_python_bundle/stdlib.zip:/data/user/0/org.test.testapp_flask/files/app/_python_bundle/modules
01-31 20:28:13.241 21005 21047 I python  : set wchar paths...
01-31 20:28:13.241   430  1306 D BandwidthController: [LG DATA] No such appUid: 10392
01-31 20:28:13.241   430  1306 D DnsProxyListener: App 10392 tries DNS query. Accept family:0 protocol:0
01-31 20:28:13.242 21005 21043 W AudioCapabilities: Unsupported mime audio/x-lg-flac
01-31 20:28:13.243 21005 21043 W AudioCapabilities: Unsupported mime audio/adpcm
...
...
...
01-31 20:28:13.402 21005 21047 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 21047 (PythonThread)
01-31 20:28:13.402   458   560 E ThermalEngine: ACTION: CLUSTER - Setting CLUSTER[1] to 1632000
01-31 20:28:13.404   458   560 E ThermalEngine: ACTION: CLUSTER - Setting CLUSTER[1] to 1689600
01-31 20:28:13.412 21005 21043 I VideoCapabilities: Unsupported profile 4 for video/mp4v-es
01-31 20:28:13.420  1319  1467 I ActivityManager: Displayed org.test.testapp_flask/org.kivy.android.PythonActivity: +479ms
01-31 20:28:13.421  1319  1467 V WindowManager: Looking for focus: 25 = Window{29f1034 u0 StatusBar}, flags=-2122055608, canReceive=false
01-31 20:28:13.421  1319  1467 V WindowManager: findFocusedWindow: Found new focus @ 17 = Window{989de75 u0 org.test.testapp_flask/org.kivy.android.PythonActivity}
01-31 20:28:13.423  1319  1467 D InputDispatcher: Window went away: Window{7e46238 u0 Starting org.test.testapp_flask}
01-31 20:28:13.434 21005 21057 W cr_CrashFileManager: /data/user/0/org.test.testapp_flask/cache/WebView/Crash Reports does not exist or is not a directory
01-31 20:28:13.435   458   560 E ThermalEngine: ACTION: CLUSTER - Setting CLUSTER[1] to 1632000
01-31 20:28:13.453   431   431 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-31 20:28:13.453   431   431 F DEBUG   : Build fingerprint: 'lge/p1_global_com/p1:6.0/MRA58K/1809319266c01:user/release-keys'
01-31 20:28:13.453   431   431 F DEBUG   : Revision: '11'
01-31 20:28:13.453   431   431 F DEBUG   : ABI: 'arm'
01-31 20:28:13.453   431   431 F DEBUG   : pid: 21005, tid: 21047, name: PythonThread  >>> org.test.testapp_flask <<<
01-31 20:28:13.454   431   431 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
01-31 20:28:13.465   458   560 E ThermalEngine: ACTION: CLUSTER - Setting CLUSTER[1] to 1536000
01-31 20:28:13.470   431   431 F DEBUG   :     r0 00000000  r1 00005237  r2 00000006  r3 d907f978
01-31 20:28:13.470   431   431 F DEBUG   :     r4 d907f980  r5 d907f930  r6 00000000  r7 0000010c
01-31 20:28:13.470   431   431 F DEBUG   :     r8 00000002  r9 f3cbdf0a  sl d907f148  fp d907ee78
01-31 20:28:13.470   431   431 F DEBUG   :     ip 00000006  sp d907ee00  lr f74160ad  pc f7418190  cpsr 400f0010
01-31 20:28:13.472   431   431 F DEBUG   : 
01-31 20:28:13.472   431   431 F DEBUG   : backtrace:
01-31 20:28:13.472   431   431 F DEBUG   :     #00 pc 00042190  /system/lib/libc.so (tgkill+12)
01-31 20:28:13.472   431   431 F DEBUG   :     #01 pc 000400a9  /system/lib/libc.so (pthread_kill+32)
01-31 20:28:13.473   431   431 F DEBUG   :     #02 pc 0001c88f  /system/lib/libc.so (raise+10)
01-31 20:28:13.473   431   431 F DEBUG   :     #03 pc 00019a41  /system/lib/libc.so (__libc_android_abort+34)
01-31 20:28:13.473   431   431 F DEBUG   :     #04 pc 000175fc  /system/lib/libc.so (abort+4)
01-31 20:28:13.473   431   431 F DEBUG   :     #05 pc 001783e0  /data/app/org.test.testapp_flask-1/lib/arm/libpython3.7m.so

@opacam Are these expected to be working? For Python 2 it seems it may not know where to load libpython2.7.so from, which would be okay, but why is Python 3 failing at Py_Initialize even though everything seems to be set up properly?

opacam commented 5 years ago

Oh, yes, it was working for both versions of python...mmmm..

I will pull the changes and I will test it again...

opacam commented 5 years ago

@inclement, the flask testapp with python3 it's working for me (compilation and runs fine on device), with the latests p4a master (I always clean the p4a build folder before doing the build) I will make a python2 build...

inclement commented 5 years ago

Thanks @opacam, I'll investigate my environment more before worrying too much about it.

opacam commented 5 years ago

Ok, python2 also working (without the last commit in master branch...I was doing the build when the merge happened)

AndreMiras commented 5 years ago

I've tried compiling with both python2 and python3 in the Docker container, but I get compilation errors. See log:

(venv) user@5bbd34e1299b:~/testapps$ python setup_testapp_python2.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --bootstrap sdl2 --requirements python3,flask,pyjnius --debug                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                [56/1788]
packages are []
running apk
WARNING: You did not supply an Android package identifier, trying org.test.testapp_python2 instead.
         This may fail if this is not a valid identifier
Including testapp/main.py
Including testapp/colours.png
[WARNING]: --ndk-version is deprecated and no longer necessary, the value you passed is ignored
[INFO]:    Will compile for the following archs: armeabi-v7a
[INFO]:    Getting Android API version from user argument: 27
[INFO]:    Available Android APIs are (19, 27)
[INFO]:    Requested API target 27 is available, continuing.
[INFO]:    Getting NDK dir from from user argument
[INFO]:    Found NDK revision 17.2.4988734
[INFO]:    Getting NDK API version (i.e. minimum supported API) from user argument
[INFO]:    Found virtualenv at /usr/bin/virtualenv
[INFO]:    Found the following toolchain versions: ['4.9']
[INFO]:    Picking the latest gcc toolchain, here 4.9
[INFO]:    No existing dists meet the given requirements!
[INFO]:    No dist exists that meets your requirements, so one will be built.
[INFO]:    Found a single valid recipe set: ['hostpython3', 'python3', 'genericndkbuild', 'setuptools', 'six', 'flask', 'pyjnius']
[INFO]:    The selected bootstrap is sdl2
[INFO]:    # Creating dist with sdl2 bootstrap
[INFO]:    Dist will have name bdisttest_python2 and recipes (python3, flask, pyjnius)
[INFO]:    Dist will also contain modules (markupsafe, click, werkzeug, itsdangerous, jinja2) installed from pip
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Recipe build order is ['hostpython3', 'python3', 'genericndkbuild', 'setuptools', 'six', 'flask', 'pyjnius']
[INFO]:    The requirements (click, itsdangerous, jinja2, markupsafe, werkzeug) were not found as recipes, they will be installed with pip.
[INFO]:    # Downloading recipes 
[INFO]:    Downloading hostpython3
[DEBUG]:   -> running mkdir -p /home/user/.local/share/python-for-android/packages/hostpython3
[INFO]:    -> directory context /home/user/.local/share/python-for-android/packages/hostpython3
[DEBUG]:   -> running basename https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
[DEBUG]:        Python-3.7.1.tgz
[INFO]:    hostpython3 download already cached, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Downloading python3
[DEBUG]:   -> running mkdir -p /home/user/.local/share/python-for-android/packages/python3
[INFO]:    -> directory context /home/user/.local/share/python-for-android/packages/python3
[DEBUG]:   -> running basename https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
[DEBUG]:        Python-3.7.1.tgz
[INFO]:    python3 download already cached, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Downloading genericndkbuild
[INFO]:    Skipping genericndkbuild download as no URL is set
[INFO]:    Downloading setuptools
[DEBUG]:   -> running mkdir -p /home/user/.local/share/python-for-android/packages/setuptools
[INFO]:    -> directory context /home/user/.local/share/python-for-android/packages/setuptools
[DEBUG]:   -> running basename https://pypi.python.org/packages/source/s/setuptools/setuptools-40.0.0.zip
[DEBUG]:        setuptools-40.0.0.zip
[INFO]:    setuptools download already cached, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Downloading six
[DEBUG]:   -> running mkdir -p /home/user/.local/share/python-for-android/packages/six
[INFO]:    -> directory context /home/user/.local/share/python-for-android/packages/six
[DEBUG]:   -> running basename https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz
[DEBUG]:        six-1.9.0.tar.gz
[INFO]:    six download already cached, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Downloading flask
[DEBUG]:   -> running mkdir -p /home/user/.local/share/python-for-android/packages/flask
[INFO]:    -> directory context /home/user/.local/share/python-for-android/packages/flask
[DEBUG]:   -> running basename https://github.com/pallets/flask/archive/0.10.1.zip
[DEBUG]:        0.10.1.zip
[INFO]:    flask download already cached, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Downloading pyjnius
[DEBUG]:   -> running mkdir -p /home/user/.local/share/python-for-android/packages/pyjnius
[INFO]:    -> directory context /home/user/.local/share/python-for-android/packages/pyjnius
[DEBUG]:   -> running basename https://github.com/kivy/pyjnius/archive/1.1.3.zip
[DEBUG]:        1.1.3.zip
[INFO]:    pyjnius download already cached, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    # Building all recipes for arch armeabi-v7a
[INFO]:    # Unpacking recipes
[INFO]:    Unpacking hostpython3 for armeabi-v7a
[DEBUG]:   -> running basename https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
[DEBUG]:        Python-3.7.1.tgz
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/hostpython3/desktop
[INFO]:    hostpython3 is already unpacked, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Unpacking python3 for armeabi-v7a
[DEBUG]:   -> running basename https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
[DEBUG]:        Python-3.7.1.tgz
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/python3/armeabi-v7a__ndk_target_21
[INFO]:    python3 is already unpacked, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Unpacking genericndkbuild for armeabi-v7a
[INFO]:    Skipping genericndkbuild unpack as no URL is set
[INFO]:    Unpacking setuptools for armeabi-v7a
[DEBUG]:   -> running basename https://pypi.python.org/packages/source/s/setuptools/setuptools-40.0.0.zip
[DEBUG]:        setuptools-40.0.0.zip
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/setuptools-python3/armeabi-v7a__ndk_target_21
[INFO]:    setuptools is already unpacked, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Unpacking six for armeabi-v7a
[DEBUG]:   -> running basename https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz
[DEBUG]:        six-1.9.0.tar.gz
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/six-python3/armeabi-v7a__ndk_target_21
[INFO]:    six is already unpacked, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Unpacking flask for armeabi-v7a
[DEBUG]:   -> running basename https://github.com/pallets/flask/archive/0.10.1.zip
[DEBUG]:        0.10.1.zip
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/flask-python3-python3/armeabi-v7a__ndk_target_21
[INFO]:    flask is already unpacked, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Unpacking pyjnius for armeabi-v7a
[DEBUG]:   -> running basename https://github.com/kivy/pyjnius/archive/1.1.3.zip
[DEBUG]:        1.1.3.zip
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/pyjnius-genericndkbuild-python3/armeabi-v7a__ndk_target_21
[INFO]:    pyjnius is already unpacked, skipping
[INFO]:    <- directory context /home/user/testapps
[INFO]:    # Prebuilding recipes
[INFO]:    Prebuilding hostpython3 for armeabi-v7a
[INFO]:    hostpython3 has no prebuild_armeabi_v7a, skipping
[INFO]:    Prebuilding python3 for armeabi-v7a
[INFO]:    python3 has no prebuild_armeabi_v7a, skipping
[INFO]:    Applying patches for python3[armeabi-v7a]
[INFO]:    python3 already patched, skipping
[INFO]:    Prebuilding genericndkbuild for armeabi-v7a
[INFO]:    genericndkbuild has no prebuild_armeabi_v7a, skipping
[INFO]:    Prebuilding setuptools for armeabi-v7a
[INFO]:    setuptools has no prebuild_armeabi_v7a, skipping
[INFO]:    Prebuilding six for armeabi-v7a
[INFO]:    six has no prebuild_armeabi_v7a, skipping
[INFO]:    Prebuilding flask for armeabi-v7a
[INFO]:    flask has no prebuild_armeabi_v7a, skipping
[INFO]:    Prebuilding pyjnius for armeabi-v7a
[INFO]:    pyjnius has no prebuild_armeabi_v7a, skipping
[INFO]:    Applying patches for pyjnius[armeabi-v7a]
[INFO]:    pyjnius already patched, skipping
[INFO]:    # Building recipes
[INFO]:    Building hostpython3 for armeabi-v7a
[INFO]:    Skipping hostpython3 (3.7.1) build, as it has already been completed
[INFO]:    Building python3 for armeabi-v7a
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/android-build
[WARNING]: Doing some hacky stuff to link properly
[DEBUG]:   -> running cp /opt/android/android-ndk-r17c/platforms/android-21/arch-arm/usr/lib/crtbegin_so.o ./
[DEBUG]:   -> running cp /opt/android/android-ndk-r17c/platforms/android-21/arch-arm/usr/lib/crtend_so.o ./
[INFO]:    <- directory context /home/user/testapps
[INFO]:    Building genericndkbuild for armeabi-v7a
[INFO]:    -> directory context /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni
[DEBUG]:   -> running ndk-build V=1
[DEBUG]:        Android NDK: WARNING:/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni/application/src/Android.mk:main: non-system libraries in linker flags: -lpython3.7m
[DEBUG]:        Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
[DEBUG]:        Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
[DEBUG]:        Android NDK:     current module
[DEBUG]:        /opt/android/android-ndk-r17c/build/core/build-binary.mk:688: Android NDK: Module main depends on undefined modules: SDL2 python_shared
[DEBUG]:        rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/*
[DEBUG]:        rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/gdbserver
[DEBUG]:        rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/gdb.setup
[DEBUG]:        make: *** No rule to make target `/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni/application/src/../../SDL/src/main/android/SDL_android_main.c', needed by `/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/obj/local/armeabi-v7a/objs/main/__/__/SDL/src/main/android/SDL_android_main.o'.  Stop.
Exception in thread background thread for pid 18545:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 1540, in wrap
    fn(*args, **kwargs)
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 2459, in background_thread
    handle_exit_code(exit_code)
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 2157, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_2:

  RAN: /opt/android/android-ndk-r17c/ndk-build V=1

  STDOUT:
Android NDK: WARNING:/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni/application/src/Android.mk:main: non-system libraries in linker flags: -lpython3.7m
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK:     current module
/opt/android/android-ndk-r17c/build/core/build-binary.mk:688: Android NDK: Module main depends on undefined modules: SDL2 python_shared
rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/*
rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/gdbserver
rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/gdb.setup
make: *** No rule to make target `/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni/application/src/../../SDL/src/main/android/SDL_android_main.c', needed by `/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/obj/local/armeabi-v7a/objs/main/__/__/SDL/src/main/android/SDL_android_main.o'.  Stop.

  STDERR:

Traceback (most recent call last):
  File "setup_testapp_python2.py", line 31, in <module>
    package_data={'testapp': ['*.py', '*.png']}
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/user/pythonforandroid/bdistapk.py", line 80, in run
    main()
  File "/home/user/pythonforandroid/toolchain.py", line 1051, in main
    ToolchainCL()
  File "/home/user/pythonforandroid/toolchain.py", line 560, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/user/pythonforandroid/toolchain.py", line 151, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/user/pythonforandroid/toolchain.py", line 192, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "/home/user/pythonforandroid/build.py", line 566, in build_recipes
    recipe.build_arch(arch)
  File "/home/user/pythonforandroid/recipes/genericndkbuild/__init__.py", line 26, in build_arch
    shprint(sh.ndk_build, "V=1", _env=env)
  File "/home/user/pythonforandroid/logger.py", line 178, in shprint
    for line in output:
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 863, in next
    self.wait()
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 792, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/user/venv/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_2:

  RAN: /opt/android/android-ndk-r17c/ndk-build V=1

  STDOUT:
Android NDK: WARNING:/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni/application/src/Android.mk:main: non-system libraries in linker flags: -lpython3.7m
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK:     current module
/opt/android/android-ndk-r17c/build/core/build-binary.mk:688: Android NDK: Module main depends on undefined modules: SDL2 python_shared
rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/* /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/*
rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/gdbserver /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/gdbserver
rm -f /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/arm64-v8a/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi-v7a/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86/gdb.setup /home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/x86_64/gdb.setup
make: *** No rule to make target `/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/jni/application/src/../../SDL/src/main/android/SDL_android_main.c', needed by `/home/user/.local/share/python-for-android/build/bootstrap_builds/sdl2/obj/local/armeabi-v7a/objs/main/__/__/SDL/src/main/android/SDL_android_main.o'.  Stop.

  STDERR:

(venv) user@5bbd34e1299b:~/testapps$

Edit: Ouch my bad, I've explicitly specified the wrong bootstrap :confused:

AndreMiras commented 5 years ago

OK so I have it working with python3. It was compiled from Docker with:

python setup_testapp_flask.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements python3,flask,pyjnius

logcat:

02-01 14:13:42.608 17693 17795 I python  : Android kivy bootstrap done. __name__ is __main__
02-01 14:13:42.608 17693 17795 I python  : AND: Ran string
02-01 14:13:42.608 17693 17795 I python  : Run user program, change dir and execute entrypoint
02-01 14:13:42.608 17693 17795 I python  : main.py was successfully called
02-01 14:13:42.608 17693 17795 I python  : this is the new main.py
02-01 14:13:42.608 17693 17795 I python  : python version is: 3.7.1 (default, Feb  1 2019, 12:34:00) 
02-01 14:13:42.608 17693 17795 I python  : [Clang 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55
02-01 14:13:42.608 17693 17795 I python  : python path is ['.', '/data/user/0/org.test.testapp_flask/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.testapp_flask/files/app/_python_bundle/modules', '/data/user/0/org.test.testapp_flask/files/app/_python_bundle/site-packages']
02-01 14:13:42.608 17693 17795 I python  : imported os
02-01 14:13:42.829  1230  1278 I ActivityManager: Displayed org.test.testapp_flask/org.kivy.android.PythonActivity: +2s19ms
02-01 14:13:43.368 17693 17795 I python  : flask1???
02-01 14:13:43.368 17693 17795 I python  : contents of this dir ['p4a_env_vars.txt', 'main.pyc', 'static', 'templates', '_python_bundle', '_loading_style.css', '_load.html', '.nomedia', 'private.version']
02-01 14:13:43.368 17693 17795 I python  : flask???
02-01 14:13:43.370 17693 17795 I python  : imported flask etc
02-01 14:13:43.370 17693 17795 I python  : importing pyjnius
02-01 14:13:43.907 17693 17795 I python  : curdir /data/data/org.test.testapp_flask/files/app
02-01 14:13:43.943 17693 17795 I python  :  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

02-01 14:13:44.071 17693 17693 I PythonActivity: Opening URL: http://127.0.0.1:5000/
02-01 14:13:44.192 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:13:44] "GET / HTTP/1.1" 200 -
02-01 14:13:44.292 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:13:44] "GET /static/style.css HTTP/1.1" 404 -
02-01 14:13:44.305 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:13:44] "GET /static/colours.png HTTP/1.1" 200 -
02-01 14:13:44.341 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:13:44] "GET /favicon.ico HTTP/1.1" 404 -
02-01 14:14:00.214 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:14:00] "GET /page2? HTTP/1.1" 200 -
02-01 14:14:00.239 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:14:00] "GET /static/style.css HTTP/1.1" 404 -
02-01 14:14:00.246 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:14:00] "GET /static/coloursinv.png HTTP/1.1" 200 -
02-01 14:14:01.430 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:14:01] "GET /? HTTP/1.1" 200 -
02-01 14:14:01.466 17693 17795 I python  : 127.0.0.1 - - [01/Feb/2019 14:14:01] "GET /static/style.css HTTP/1.1" 404 -
misl6 commented 2 years ago

Closing as now the flask test app works fine onpython3 (python2 has been removed)