Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ctypes.util.find_library() not finding any libraries on Android #1624

Merged
merged 1 commit into from Jan 30, 2019
Merged

Fix ctypes.util.find_library() not finding any libraries on Android #1624

merged 1 commit into from Jan 30, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jan 29, 2019

This is finally my long-delayed followup to #1517 to fix ctypes.util.find_library() for Python 3. It should fix the last somewhat showstopper bug to using Python 3 & ctypes out of the box on p4a master ❤️

done & tested (with real world python3 app that uses ctypes)

@ghost ghost changed the title [WIP] Fix ctypes.util.find_library() not finding any libraries on Android Fix ctypes.util.find_library() not finding any libraries on Android Jan 29, 2019
@inclement
Copy link
Member

Just wondering, does ctypes respect $LD_LIBRARY_PATH on Android? I've used this successfully for other purposes but not sure if python's logic will use it correctly.

If not it isn't a problem to add a patch.

@ghost
Copy link
Author

ghost commented Jan 30, 2019

@inclement very interesting idea. So your suggestion is to try to set LD_LIBRARY_PATH on startup e.g. with some one-liner in start.c or similar?

We would need someone to test it with an old phone though (old Android version), some things like that change sometimes on Android

@inclement
Copy link
Member

@Jonast Exactly. For ctypes that should work the same on any Android version, as long as ctypes checks LD_LIBRARY_PATH. I checked the source and it looks like it does on the desktop, so that should work unless it gets messed up by not recognising what platform it's running on.

I guess this could solve some problems for other library loading as well, I didn't think about that before. Maybe it could obselete the explicit library loading in PythonUtil.java, but not sure.

@ghost ghost changed the title Fix ctypes.util.find_library() not finding any libraries on Android [WIP] Fix ctypes.util.find_library() not finding any libraries on Android Jan 30, 2019
@ghost
Copy link
Author

ghost commented Jan 30, 2019

@inclement neat idea! I am marking this WIP for now until I investigated the LD_LIBRARY_PATH alternative

@ghost ghost changed the title [WIP] Fix ctypes.util.find_library() not finding any libraries on Android Fix ctypes.util.find_library() not finding any libraries on Android Jan 30, 2019
@ghost
Copy link
Author

ghost commented Jan 30, 2019

@inclement okay, so unless I screwed it up totally, relative paths don't work in LD_LIBRARY_PATH. (the environment was set for sure, I see it printed at runtime in adb/logcat) Now while absolute paths are possible, this would need to be combined in start.c and would be a little ugly. I'm actually not sure I would prefer that over this relatively separate & clean patch, since start.c is one of the few files I would actually want to not add more functionality to - C is simply much more annoying to maintain in the long run.

What are your thoughts on this? Should I also give the absolute path a try, or are we going to go with this patch similar to how the Python 2 recipe already does it?

@inclement
Copy link
Member

inclement commented Jan 30, 2019

I would be interested to know if the absolute path would work. I suspect not, I'm pretty sure nothing that reads LD_LIBRARY_PATH would really care about it.

If you can check it then fine, we can merge this patch and it's completely fine, I'll look into making python get the paths in a better way some other time.

@ghost
Copy link
Author

ghost commented Jan 30, 2019

@inclement ok hang on, I'll hack it into my own main.py startup code before the imports and check what happens. That should have the same effects, right? Should work well enough to see if it works with absolute paths without me bothering with a proper start.c patch

@inclement
Copy link
Member

That's fine, I'm really wondering just in case it would work at all for future reference.

Copy link
Member

@inclement inclement left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay for now, it's interesting to wonder how python should actually find the correct file but it seems there's no good solution within the ctypes code right now.

@inclement inclement merged commit 0b71851 into kivy:master Jan 30, 2019
@inclement
Copy link
Member

Thanks!

@ghost ghost deleted the fix_ctypes_util branch January 31, 2019 00:13
@ghost
Copy link
Author

ghost commented Jan 31, 2019

@inclement ok, I tested this & printed out the absolute path & resulting env & even added os.listdir() output to be very sure I specified the correct folder and LD_LIBRARY_PATH was actually set, and it doesn't work. So no dice with LD_LIBRARY_PATH even with absolute path, it seems (unless I made some other fundamental mistake I'm not aware of 😄 but I can't think of anything)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant