ITの隊長のブログ

ITの隊長のブログです。Pythonを使って仕事しています。最近は機械学習をさわりはじめたお(^ω^ = ^ω^)

【起動できませんでした】面白そうなOSS見つけた。「python-for-android」

スポンサードリンク

github.com

README.mdやドキュメントだけでは起動できず、ソースを読んでオプションを試してみたけど、結局Android起動まではできませんでした。

また試してみるかもしれないので、メモしておく。

とりあえず試した

Getting Started — python-for-android 0.1 documentation

$ pip install python-for-android
$ p4a apk --requirements=kivy --private obasann/ --package=net.inclem.planewavessdl2 --name="planewavessdl2" --version=0.5 --bootstrap=sdl2

pipでインストールできた。んで、よくわからんけど、起動っぽいコマンドを実行。

NDKのパスが見つからん。バージョンが見つからん。

エラー発生です。

[WARNING]: Android SDK dir was not specified, exiting.

sdkがないー。(そのあとにndkがないー!)と言われた。

コマンドで指定してあげることもできるが、exportしてあげたほうが楽かも。

Getting Started — python-for-android 0.1 documentation

$ export ANDROIDSDK="$HOME/Library/Android/sdk"
$ export ANDROIDNDK="$HOME/Library/Android/ndk"
$ export ANDROIDNDKVER="r10e"  # Version of the NDK you installed
$ p4a apk --requirements=kivy --private obasann/ --package=net.inclem.planewavessdl2 --name="planewavessdl2" --version=0.5 --bootstrap=sdl2

AttributeError: ‘Context’ object has no attribute ‘hostpython’

build中に踏んだ。

github.com

よくわからんが、hostpython2ってのがbundle?されているやつをそのまま使うのはダメらしい。

なので、再度ビルドする必要があるとのこと。どないせーちゅーねん。

Troubleshooting — python-for-android 0.1 documentation

This is a known bug in some releases. To work around it, add your python requirement explicitly, e.g. –requirements=python2,kivy. This also applies when using buildozer, in which case add python2 to your buildozer.spec requirements.

ふむ。オプションを追加してあげれば良いのね。

$ p4a apk --requirements=kivy --private obasann/ --package=net.inclem.planewavessdl2 --name="planewavessdl2" --version=0.5 --bootstrap=sdl2 --requirements=python2,kivy

コンパイルに結構時間かかっている感じ。

謎のエラー発生

そもそもこのエラーの見方がわからん。

これを解決する時間がないので、また今度(´・ω・`)

[INFO]:    -> directory context /home/user/.python-for-android/build/bootstrap_builds/sdl2-python2/jni
[INFO]:    -> running ndk-build V=1
           working: /home/user/Library/Android/ndk/build/core/build-binary.mk:700: *** Android NDK: Aborting (set APP_ALLOW_MI...(and 58 more)  Exception in thread background thread for pid 69768:
Traceback (most recent call last):
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/threading.py", line 911, in _bootstrap_inner
    self.run()
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/threading.py", line 859, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 1540, in wrap
    fn(*args, **kwargs)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 2455, in background_thread
    handle_exit_code(exit_code)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 2153, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_2:

  RAN: /home/user/Library/Android/ndk/ndk-build V=1

  STDOUT:
Android NDK: WARNING: APP_PLATFORM android-15 is larger than android:minSdkVersion 12 in /home/user/.python-for-android/build/bootstrap_builds/sdl2-python2/AndroidManifest.xml
Android NDK: WARNING:/home/user/.python-for-android/build/bootstrap_builds/sdl2-python2/jni/src/Android.mk:main: non-system libraries in linker flags: -lpython2.7
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
/home/user/Library/Android/ndk/build/core/build-binary.mk:687: Android NDK: Module main depends on undefined modules: python_shared
/home/user/Library/Android/ndk/build/core/build-binary.mk:700: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.


  STDERR:


Traceback (most recent call last):
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/bin/p4a", line 11, in <module>
    sys.exit(main())
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/toolchain.py", line 754, in main
    ToolchainCL()
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/toolchain.py", line 343, in __init__
    getattr(self, command_method_name)(unknown)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/toolchain.py", line 93, in wrapper_func
    build_dist_from_args(ctx, dist, dist_args)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/toolchain.py", line 138, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/build.py", line 561, in build_recipes
    recipe.build_arch(arch)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/recipes/sdl2/__init__.py", line 29, in build_arch
    shprint(sh.ndk_build, "V=1", _env=env)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/pythonforandroid/logger.py", line 173, in shprint
    for line in output:
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 863, in next
    self.wait()
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 792, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/user/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_2:

  RAN: /home/user/Library/Android/ndk/ndk-build V=1

  STDOUT:
Android NDK: WARNING: APP_PLATFORM android-15 is larger than android:minSdkVersion 12 in /home/user/.python-for-android/build/bootstrap_builds/sdl2-python2/AndroidManifest.xml
Android NDK: WARNING:/home/user/.python-for-android/build/bootstrap_builds/sdl2-python2/jni/src/Android.mk:main: non-system libraries in linker flags: -lpython2.7
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
/home/user/Library/Android/ndk/build/core/build-binary.mk:687: Android NDK: Module main depends on undefined modules: python_shared
/home/user/Library/Android/ndk/build/core/build-binary.mk:700: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.


  STDERR: