-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
Crash loading pydantic_core
on Android
#1544
Comments
Thanks for the report. The underlying issue here is that Chaquopy doesn't provide a package for pydantic. As of V2, pydantic uses a Rust implementation, which is undeniably faster, but is platform specific, and therefore needs to be compiled specifically for Android (and, for that matter, any other platform - but they provide pre-compiled wheels for Windows, Linux and macOS, so it's not as much of an issue). Compiling Rust binary packages for Android is possible (as in, the Rust platform tooling exists), but I don't believe the Chaquopy tooling for building binary wheels currently supports Rust packages (@mhsmith can correct me here if I'm wrong on this front). You can check the list of currently supported Android packages here and here; You've already linked the open request to add a recipe for pydantic-core. It looks like you've discovered the workaround as well - downgrade Pydantic to v1. This makes it a pure-python package, removing the problem. Of course, as you note, you're then not using Pydantic 2 :-) The thing that is weird from your stack trace is that the build is succeeding, beacuse it is happily installing the macOS binary wheel for pydantic-core... even though it's an Android build. Ordinarily, if you try to install a binary package Chaquopy doesn't support, it raises an error because the dependency can't be satisfied. However, it's satisfying the requirement with a macOS package, so the build succeeds, but then at runtime, there's no Android-compatible binary module present, and the app crashes. My guess is that the issue is that your explicit dependency is on pydantic, which is a cross-platform wheel; but pydantic-core is a dependency, and resolving that dependency is causing a macOS specific wheel to be selected (because you're running the build on macOS, and for most Python installs, the build machine is the same as the deployment machine). This suggests to me that there's a bug in Chaquopy's dependency resolver; but I'll keep this issue open in case Briefcase is contributing to the problem somehow. |
That's correct: I've built one Rust package in the past (tokenizers), but we haven't yet added generalized Rust support to the package build tool.
Relevant section of the log:
Since it's taking the wheel from pip's wheel cache, rather than its HTTP cache, I think what happened is that it built a macOS wheel locally on a previous attempt, which was only possible because the Rust tools were installed on the build machine. If I try to install pydantic on a machine without the Rust tools, then it fails as expected:
In the absence of any general way to tell a PEP 517 backend to disable native compilation, I don't think there's much we can do about this. So I'll close this issue, and let's keep any futher discussion in the Chaquopy issue linked above. |
Hi, what's the status for support lib implemented with rust on the android platform? @freakboy3742 @mhsmith |
For |
Describe the bug
A full bug reproduction project is here: https://github.com/caarmen/beeware-helloworld
The
briefcase build android
command doesn't seem to package the pydantic_core library inside the app, which causes app crashes at runtime, on app startup.Steps to reproduce
Clone the bug reproduction project: https://github.com/caarmen/beeware-helloworld
pip install -r requirements.txt
helloworld
subdirectory:cd helloworld
briefcase dev
briefcase create android
briefcase build android
adb install -r build/helloworld/android/gradle/app/build/outputs/apk/debug/app-debug.apk
adb lolcat -v threadtime > /tmp/logcat.txt 2>&1 &
/tmp/logcat.txt
:Expected behavior
Expected behavior: the app ui appears.
Screenshots
This is the result on an Android device (Google android emulator here):
Environment
Logs
briefcase.2023_11_18-23_24_52.create.log
briefcase.2023_11_18-23_25_54.build.log
Additional context
Related:
There's a suggested workaround to use python 3.8 and a 1.x version of pydantic. I didn't try with python 3.8, but the graphql library seems to rely on pydantic 2.
Did a test (still on python 3.11) to downgrade pydantic (and remove the dependency to pydantic_core). The app installs and works fine like that.
Would be nice to have pydantic 2 support though. 🙏🏻
If this is not a problem in briefcase, but in chaquopy, don't hesitate to close this issue :)
The text was updated successfully, but these errors were encountered: