failed to import android package

297 views
Skip to first unread message

Robert Flatt

unread,
Dec 5, 2018, 10:02:27 PM12/5/18
to Kivy users support

I want to call a function from the 'android' package, I understand this is only available within the .apk which is built by p4a.


from android.runnable import run_on_ui_thread


Fails on an android device, "adb logcat" shows:


12-04 19:41:58.758 24718 24746 I python  :  ModuleNotFoundError: No module named 'android'

If I unzip the .apk and unpack the tarball "private.mp3" I see:


_python_bundle/site-packages/jnius_config.py
 _python_bundle
/site-packages/setup.py
 _python_bundle
/site-packages/six.py
 
 _python_bundle
/site-packages/jnius:
 __init__
.py  jnius.so  reflect.py  signatures.py  src
 
 _python_bundle
/site-packages/kivy:
 __init__
.py   compat.py   factory_registers.py  logger.py       support.py
 _clock
.so     config.py   garden                metrics.py      tools
 _event
.so     context.py  geometry.py           modules         uix
 adapters      core        gesture
.py            multistroke.py  utils.py
 animation
.py  data        graphics              network         vector.py
 app
.py        deps        input                 parser.py       version.py
 atlas
.py      effects     interactive.py        properties.so   weakmethod.py
 
base.py       event.py    lang                  resources.py    weakproxy.so
 cache
.py      extras      lib                   setupconfig.py
 clock
.py      factory.py  loader.py             storage


The "kivy","jnius", and "six" packages are all there, but no "android". So I think I understand why I got the error.


So how does the "android" package added to the ".apk" ?


My .p4a is :


 --private .
 
--package=com.fishes.fl
 
--name Fl
 
--bootstrap=sdl2
 
--requirements=python3,kivy
 
--arch=armeabi-v7a
 
--permission INTERNET
 
--orientation sensor
 
--icon chart.png
 
--presplash chart.jpg
 
--sdk_dir /home/bobf/androidtools/sdk
 
--ndk_dir /home/bobf/androidtools/android-ndk-r17c
 
--ndk_version 17c
 
--android_api 28
 
--ndk-api 21
 
--version 0.3.14


I tried changing the --requirements (tried "android" as first, middle, and last positions!):


--requirements=python3,kivy,android


But p4a died, somehow the --requirements value had become a --bootstrap  value :(

 

 File "/usr/local/lib/python3.6/dist-packages/pythonforandroid/recipes/android/__init__.py", line 33, in prebuild_arch
     bootstrap
= bootstrap_name = self.ctx.bootstrap.name.decode('utf-8')
 
AttributeError: 'str' object has no attribute 'decode'


Possibly related, I note in "adb logcat" that --presplash also depends on the "android" package.


12-04 19:11:06.509 22984 23011 I python  : [WARNING] [Base        ] Failed to import "android" module. Could not remove android presplash.

Since this occurs before my app entry point, it must be required that including "android" package is the default (it is not see private.mp3 above), or a build option. Or something else I didn't see ;)


My question is what is the "p4a" build option that adds "android" to the .apk ?



Robert Flatt

unread,
Dec 5, 2018, 11:34:19 PM12/5/18
to Kivy users support
I have a workaround, that adds android to the .apk. In addition to:
--requirements=python3,kivy,android
Edit :
/usr/local/lib/python3.6/dist-packages/pythonforandroid/recipes/android/__init__.py
Remove that utf-8 decoding (you have to have sudo):
       #bootstrap = bootstrap_name = self.ctx.bootstrap.name.decode('utf-8')
        bootstrap
= bootstrap_name = self.ctx.bootstrap.name

Anybody got a less drastic solution?

Robert Flatt

unread,
Dec 6, 2018, 8:17:41 PM12/6/18
to Kivy users support
Reply all
Reply to author
Forward
0 new messages