How to link library to android /system/lib/libz.so

567 views
Skip to first unread message

mung kie

unread,
Oct 27, 2015, 12:35:08 PM10/27/15
to Kivy users support

I want to use pil and it requires zlib decode and thus libz, how can I get recipe to link to android zlib or compile zlib for inclusion in the p4a apk?

This is using the new build system.

Alexander Taylor

unread,
Oct 27, 2015, 1:37:46 PM10/27/15
to Kivy users support
libz.so will be in the android ndk, so it should automatically be linkable (i.e. in a normal filepath).

You can check the old-toolchain pil recipe to see how it works.

mung kie

unread,
Oct 27, 2015, 8:31:06 PM10/27/15
to Kivy users support
Thanks for the reply, I am a total newbie with p4a so not sure I have the recipe correctly, I post it below so others can check it:

    def build_armeabi(self):
        arch
= ArchAndroid(self.ctx)
        env
= self.get_recipe_env(arch)
        env
['CFLAGS'] = env['CFLAGS'] + ' -I{jni_path}/png -I{jni_path}/jpeg  -I{jni_path}/freetype/include/freetype'.format( jni_path=join(self.ctx.bootstrap.build_dir, 'jni'))
        env
['CFLAGS'] = env['CFLAGS'] + ' -DHAVE_LIBZ -DHAVE_LIBJPEG '
        env
['LDFLAGS'] = env['LDFLAGS'] + ' -L{libs_path} -L{src_path}/obj/local/{arch} -lm -lz'.format( libs_path=self.ctx.libs_dir, src_path=self.ctx.bootstrap.build_dir, arch=env['ARCH'])
        env
['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink')
       
with current_directory(self.get_build_dir('armeabi')):
            info
('hostpython is ' + self.ctx.hostpython)
            hostpython
= sh.Command(self.ctx.hostpython)
            shprint
(hostpython, 'setup.py', 'install', '-O2', _env=env)

            info
('strip is ' + env['STRIP'])
            build_lib
= glob.glob('./build/lib*')
           
assert len(build_lib) == 1
           
print('stripping pil')
            shprint
(sh.find, build_lib[0], '-name', '*.o', '-exec',
                    env
['STRIP'], '{}', ';')
        python_install_path
= join(self.ctx.build_dir, 'python-install')

The logcat error message is as follows:

D/dalvikvm( 4178): Trying to load lib /data/data/net.org.pid/files/lib/python2.7/lib-dynload/_imaging.so 0x4129d540
E
/dalvikvm( 4178): dlopen("/data/data/net.org.pid/files/lib/python2.7/lib-dynload/_imaging.so") failed: Cannot load library: soinfo_relocate(linker.cpp:987): cannot locate symbol "inflateInit_" referenced by "_imaging.so"...
I
/python  ( 4178): Starting audio thread
I
/python  ( 4178): Initialize Python for Android
I
/python  ( 4178): ['/data/data/net.org.pid/files/lib/python2.7/site-packages', '/data/data/net.org.pid/files/lib/site-python']
I
/python  ( 4178): Android path ['/data/data/net.org.pid/files/lib/python27.zip', '/data/data/net.org.pid/files/lib/python2.7', '/data/data/net.org.pid/files/lib/python2.7/lib-dynload', '/data/data/net.org.pid/files/lib/python2.7/site-packages', '/data/data/net.org.pid/files', '/data/data/net.org.pid/files/lib/python2.7/site-packages/PIL']
I
/python  ( 4178): Android kivy bootstrap done. __name__ is __main__
I
/python  ( 4178): Run user program, change dir and execute main.py
I
/python  ( 4178): [WARNING           ] [Config      ] Older configuration version detected (0 instead of 14)
I
/python  ( 4178): 2015-10-28 00:20:01,558 WARNING: kivy: [Config      ] Older configuration version detected (0 instead of 14)
I
/python  ( 4178): [WARNING           ] [Config      ] Upgrading configuration in progress.
I
/python  ( 4178): 2015-10-28 00:20:01,559 WARNING: kivy: [Config      ] Upgrading configuration in progress.
I
/python  ( 4178): [INFO              ] [Logger      ] Record log in /data/data/net.org.pid/files/.kivy/logs/kivy_15-10-28_0.txt
I
/python  ( 4178): 2015-10-28 00:20:01,576 INFO: kivy: [Logger      ] Record log in /data/data/net.org.pid/files/.kivy/logs/kivy_15-10-28_0.txt
I
/python  ( 4178): [INFO              ] [Kivy        ] v1.9.1-dev
I
/python  ( 4178): 2015-10-28 00:20:01,573 INFO: kivy: [Kivy        ] v1.9.1-dev
I
/python  ( 4178): [INFO              ] [Python      ] v2.7.2 (default, Oct 15 2015, 15:14:51)
I
/python  ( 4178): [GCC 4.9 20140827 (prerelease)]
I
/python  ( 4178): 2015-10-28 00:20:01,579 INFO: kivy: [Python      ] v2.7.2 (default, Oct 15 2015, 15:14:51)
I
/python  ( 4178): [GCC 4.9 20140827 (prerelease)]
I
/python  ( 4178): [INFO              ] [Factory     ] 177 symbols loaded
I
/python  ( 4178): 2015-10-28 00:20:01,619 INFO: kivy: [Factory     ] 177 symbols loaded
E
/linker  ( 4178): find_library(linker.cpp:901): "/data/data/net.org.pid/files/lib/python2.7/site-packages/PIL/_imaging.so" failed to load previously
I
/python  ( 4178): [INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_pygame, img_pil (img_ffpyplayer ignored)
I
/python  ( 4178): 2015-10-28 00:20:02,717 INFO: kivy: [Image       ] Providers: img_tex, img_dds, img_gif, img_pygame, img_pil (img_ffpyplayer ignored)
I
/python  ( 4178): Unable to import libraries from PIL
I
/python  ( 4178): Unable to import libraries from PIL
I
/python  ( 4178):  Traceback (most recent call last):
I
/python  ( 4178): 2015-10-28 00:20:03,324 WARNIN

I hope someone can offer some help or suggestions on how to trace what is causing the error.

Alexander Taylor

unread,
Oct 28, 2015, 6:50:43 AM10/28/15
to kivy-...@googlegroups.com
I haven't looked into this, but one observation is that I haven't
actually tested the freetype recipe so maybe that doesn't work (though
it might not be the only issue even if so).

On 28/10/15 00:31, mung kie wrote:
> Thanks for the reply, I am a total newbie with p4a so not sure I have
> the recipe correctly, I post it below so others can check it:
>
> |
> defbuild_armeabi(self):
> arch =ArchAndroid(self.ctx)
> env =self.get_recipe_env(arch)
> env['CFLAGS']=env['CFLAGS']+' -I{jni_path}/png -I{jni_path}/jpeg
> -I{jni_path}/freetype/include/freetype'.format(jni_path=join(self.ctx.bootstrap.build_dir,'jni'))
> env['CFLAGS']=env['CFLAGS']+' -DHAVE_LIBZ -DHAVE_LIBJPEG '
> env['LDFLAGS']=env['LDFLAGS']+' -L{libs_path}
> -L{src_path}/obj/local/{arch} -lm
> -lz'.format(libs_path=self.ctx.libs_dir,src_path=self.ctx.bootstrap.build_dir,arch=env['ARCH'])
> env['LDSHARED']=join(self.ctx.root_dir,'tools','liblink')
> withcurrent_directory(self.get_build_dir('armeabi')):
> info('hostpython is '+self.ctx.hostpython)
> hostpython =sh.Command(self.ctx.hostpython)
> shprint(hostpython,'setup.py','install','-O2',_env=env)
>
> info('strip is '+env['STRIP'])
> build_lib =glob.glob('./build/lib*')
> assertlen(build_lib)==1
> print('stripping pil')
> shprint(sh.find,build_lib[0],'-name','*.o','-exec',
> env['STRIP'],'{}',';')
> python_install_path =join(self.ctx.build_dir,'python-install')
> (4178):find_library(linker.cpp:901):"/data/data/net.org.pid/files/lib/python2.7/site-packages/PIL/_imaging.so"failed
> to load previously
> I/python (4178):[INFO ][Image
> ]Providers:img_tex,img_dds,img_gif,img_pygame,img_pil (img_ffpyplayer
> ignored)
> I/python (4178):2015-10-2800:20:02,717INFO:kivy:[Image
> ]Providers:img_tex,img_dds,img_gif,img_pygame,img_pil (img_ffpyplayer
> ignored)
> I/python (4178):Unableto importlibraries fromPIL
> I/python (4178):Unableto importlibraries fromPIL
> I/python (4178): Traceback(most recent call last):
> I/python (4178):2015-10-2800:20:03,324WARNIN
> |
>
> I hope someone can offer some help or suggestions on how to trace what
> is causing the error.
>
>
>
> On Tuesday, October 27, 2015 at 5:37:46 PM UTC, Alexander Taylor wrote:
>
> libz.so will be in the android ndk, so it should automatically be
> linkable (i.e. in a normal filepath).
>
> You can check the old-toolchain pil recipe to see how it works.
>
> On Tuesday, 27 October 2015 16:35:08 UTC, mung kie wrote:
>
>
> I want to use pil and it requires zlib decode and thus libz, how
> can I get recipe to link to android zlib or compile zlib for
> inclusion in the p4a apk?
>
> This is using the new build system.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/-Bo2MTOmVEc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


signature.asc

mung kie

unread,
Oct 28, 2015, 9:07:46 AM10/28/15
to Kivy users support
freetype maybe a problem, but is definitly not the major problem as the error is the same if freetype is not included.

basically seems that the imaging lib cannot find the inflateInit_ function which is part of zlib, not sure what the 'soinfo_relocate' does or if lzib is linked to properly by _imaging.so?


E/dalvikvm( 4178): dlopen("/data/data/net.org.pid/files/lib/python2.7/lib-dynload/_imaging.so") failed: Cannot load library: soinfo_relocate(linker.cpp:987): cannot locate symbol "inflateInit_" referenced by "_imaging.so"...

Can you advise how to trace what is going on on the android device?

Can I login to android with the 'adb shell' and open the p4a package and check what files it contains and if they are linked to correctly??

What are the paths to installed .apk files and how can I access them?

I tried using ldd in the buildozer environment but there is no armeabi ldd version to show which libraries are linked to and I don't know what other methods of error tracing are available.

mung kie

unread,
Oct 29, 2015, 12:58:27 PM10/29/15
to Kivy users support

Just some more info that maybe help work out what is going on:

grepping for InflateInit
.local$ grep -re inflateInit_ share/python-for-android/dists/
Binary file share/python-for-android/dists/unnamed_dist_1/private/lib/python2.7/lib-dynload/_imaging.so matches
Binary file share/python-for-android/dists/unnamed_dist_1/private/lib/python2.7/site-packages/PIL/_imaging.so matches
Binary file share/python-for-android/dists/unnamed_dist_1/libs/armeabi/libsdl_image.so matches
Binary file share/python-for-android/dists/unnamed_dist_1/python-install/lib/python2.7/lib-dynload/_imaging.so matches
Binary file share/python-for-android/dists/unnamed_dist_1/python-install/lib/python2.7/site-packages/PIL/_imaging.so matches

from the grep output it seems libsdl_image.so uses inflateInit_, but there is no libz.so contained in the dist???

And for reference the command used to create the apk:

p4a apk --requirements=pi3d,vispy2,pil  --permission INTERNET,ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION --private ./publ/ --package=net.org.pid --name="pid" --version=0.3 --blacklist blacklist.txt

Does anyone have any ideas?


Reply all
Reply to author
Forward
0 new messages