Hi, I am new to python for android tool and kivy. Right now I have a project to try to run python and c++ code on android via p4a tool. After reading the doc, I still don't understand how to apply p4a tool especially not know how to apply private recipe.
For example, I have a folder ~/test. The structure inside is like the following:
~/test
main.py
p4a-recipes
rectangle
__init__.py
src
setup.py
rect
Rectangle.cpp
Rectangle.h
rect.pyx
My main.py is very simple, the snippet is :
import rectangle as r
r.PyRectangle(0,0,10,10)
print("Hello, World!")
The code inside __init__.py is :
from pythonforandroid.recipe import CythonRecipe, IncludedFilesBehaviour
from pythonforandroid.util import current_directory
from pythonforandroid import logger
from os.path import join
class RectangleRecipe(IncludedFilesBehaviour, CythonRecipe):
name = 'rectangle'
version = None
url = None
src_filename = 'src'
depends = ['sdl2', 'pyjnius']
def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
# Manipulate the env here if you want
return env
def should_build(self, arch):
# Add a check for whether the recipe is already built if you
# want, and return False if it is.
return True
def prebuild_arch(self, arch):
super().prebuild_arch(self)
def build_arch(self, arch):
super().build_arch(self)
def postbuild_arch(self, arch):
super().prebuild_arch(self)
# Do anything you want after the build, e.g. deleting
# unnecessary files such as documentation
recipe = RectangleRecipe()
The setup.py is :
from distutils.core import setup
from distutils.extension import Extension
extensions = [Extension('rectangle', ['./rect/Rectangle.cpp'])]
setup(name = "rectangle",packages=['rect'],
package_dir={'rect': 'rect'},
ext_modules= extensions)
The rect.pyx is :
# distutils: language = c++
# distutils: sources = Rectangle.cpp
cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Rectangle:
Rectangle(int, int, int, int) except +
int x0, y0, x1, y1
int getLength()
int getHeight()
int getArea()
void move(int, int)
cdef class PyRectangle:
cdef Rectangle *thisptr # hold a C++ instance which we're wrapping
def __cinit__(self, int x0, int y0, int x1, int y1):
self.thisptr = new Rectangle(x0, y0, x1, y1)
def __dealloc__(self):
del self.thisptr
def getLength(self):
return self.thisptr.getLength()
def getHeight(self):
return self.thisptr.getHeight()
def getArea(self):
return self.thisptr.getArea()
def move(self, dx, dy):
self.thisptr.move(dx, dy)
So if I run the command:
p4a apk --private $HOME/test --package=org.example.myapp --name "MyFirstKiviApplication" --version 0.1 --bootstrap=sdl2 --requirements=python3,kivy,rectangle
there is the error:
ERROR: Could not find a version that satisfies the requirement rectangle (from versions: none)
ERROR: No matching distribution found for rectangle
So I am so confused how to apply this private recipe to the apk. Would anyone help me on this issue? Thank you very much in advance.