Can I create a gRPC recipe for Python4Android to build a firestore kivy app?

33 Views Asked by At

Main problem

I need help to write a Python4Android recipe for gRPC.

Context

I am building a kivy (python) app for Android that makes use of the Cloud Firestore Database. It all was going smoothly until I faced an issue with the Firebase package dependency on gRPC package.

I am building using buildozer on the WSL of my Windows computer (x86_64), while my target is an Android phone (arm64). The problem here is that gRPC is not purely python but has some C elements. Since I am not building the apk in a arm64 device, these components are not compiled for arm64. Thus, when I try running the apk on the phone, it crashes because the file is compiled for a different architecture.

Usually (and correct me if I am wrong), this is no problem because many packages have python4android recipes that takes care of this by choosing the precompiled elements for the target architecture instead of the building machine architecture. Sadly, gRPC has no official recipe (in https://github.com/kivy/python-for-android/tree/develop/pythonforandroid/recipes). I am mind-boggled about this because it means that nobody is using kivy with Firestore for android, which is hard to believe.

I have spent the past two weeks roaming posts and github issues and I am not the first person to suffer this. However, I haven't found any working solution since most of those threads were dead ends. I haven't found any workaround to make Firestore work without gRPC so my only option is to make the custom recipe for Python4Android. (If you know other solution I would gladly embrace it!)

Current state

The recipe I have to build should be quite simple (I think) because in PyPI there is already a wheel for gRPC for arm64 in:

https://pypi.org/project/grpcio/#files

However, I don't know how to tell the recipe to use it (and if it is enough). I have tried a lot of things for the "__init__.py" of the recipe without success. The instructions to create a custom recipe (https://github.com/Android-for-Python/Android-for-Python-Users#creating-a-recipe) are quite vague because I believe it is very dependent on the package.

I have no problem with making buildozer use the custom recipe, that is covered.

My problem is that I am completely stuck and at a loss regarding writing the recipe and I don't know how to proceed.

I would really appreciate some help or guidance on this.

This is my starting point but it just explodes in building because it simply doesn't do what it should:

# coding=utf-8

from pythonforandroid.recipe import CythonRecipe

class PYGRPCIORecipe(CythonRecipe):
    name = 'pygrpcio'
    version = 'v1.62.1'
    url = 'https://github.com/grpc/grpc/archive/{version}.zip'
    site_packages_name = 'grpcio'
    depends = ['grpc', 'protobuf', 'absl-py', 'libssl-dev', 'openssl', 'setuptools', 'pkg_resources']
    cython_args = []
    

recipe = PYGRPCIORecipe()

As a note, I realize that this problem would be solved if I just built the apk in a arm64 machine directly. Unfortunately, I don't have access to one. I tried it in my Raspi4 but, even if it is arm64, building kivy buildozer is not supported for Raspi (and it is crazy time expensive).

Thank you in advance!

0

There are 0 best solutions below