unseenlaser / python-for-android

Automatically exported from code.google.com/p/python-for-android
Apache License 2.0
0 stars 0 forks source link

ctypes module can't import third party libraries #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

>>> from ctypes import cdll
<PyDLL 'libpython2.6.so', handle b000cac4 at 400863f0>
>>> libc = cdll.LoadLibrary('libc.so')
>>> libc = cdll.LoadLibrary('/sdcard/lib/libc.so')
>>> libsdl = cdll.LoadLibrary('/sdcard/lib/libSDL.so')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
  File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
OSError: Cannot load library: load_segments[907]: 16582 failed to map segment 
from 'libSDL.so' @ 0x80400000 (0x00070da8). p_vaddr=0x00000000 
p_offset=0x00000000
>>> 

$ ls -l /sdcard/lib
----rwxr-x system   sdcard_rw   478824 2011-01-31 16:25 libSDL.so
----rwxr-x system   sdcard_rw   278276 2011-02-15 20:10 libc.so

# md5sum /system/lib/libc.so /sdcard/lib/libc.so
07724f989fdb0134370eedc1ad9929cc  /system/lib/libc.so
07724f989fdb0134370eedc1ad9929cc  /sdcard/lib/libc.so

What is the expected output? What do you see instead?

So ctypes successfully imports libc.so implicitly from /system/lib, and also 
loads an identical copy in /sdcard/lib.  However, loading a third party library 
does not work.  libSDL.so is the latest libSDL port to Android, from a working 
demo app.  Other third party libraries extracted from .apk files also fail to 
load under ctypes.

What version of the product are you using? On what operating system?

I'm running Android 2.2 on a rooted HTC EVO.

Please provide any additional information below.

Original issue reported on code.google.com by paul.dan...@gmail.com on 18 Feb 2011 at 5:11

GoogleCodeExporter commented 8 years ago
This will not work. You can't load dynamic libraries from /sdcard it's mounted 
with permissions to prevent that.

You should create a zip file with this c files and use the Py4A installer to 
install it (if you change the extension to egg then it will automatically let 
you uninstall it later)

For testing purposes I suggest you use adb to push the files into /tmp and load 
from there, that works on some devices

Original comment by naranjo....@gmail.com on 18 Feb 2011 at 5:38

GoogleCodeExporter commented 8 years ago
But I was able to load shared libraries from /sdcard.  That's precisely what I 
tested when I copied libc.so over to the same directory as libSDL.so on 
/sdcard/lib.  I can load /sdcard/lib/libc.so, but not /sdcard/lib/libSDL.so.

Now I'm suspecting dependencies.

I will try zipping the dependent libraries together to see if that helps.  
Thanks.

Original comment by paul.dan...@gmail.com on 18 Feb 2011 at 5:51

GoogleCodeExporter commented 8 years ago
do print libc, I'm quite sure you got the catched libc, you can't load a 
library with teh same name more than once in Android AFAIK.

Original comment by naranjo....@gmail.com on 18 Feb 2011 at 6:12

GoogleCodeExporter commented 8 years ago
python_for_android_r6.apk has a basic file handler, that may simplify managing 
these issues.
I can confirm that Android will not load .so files directly from sdcard.

Original comment by rjmatthews62 on 20 Mar 2011 at 7:08

GoogleCodeExporter commented 8 years ago

Original comment by rjmatthews62 on 20 Apr 2011 at 3:47