Skip to content

Commit cae8a85

Browse files
mzakharomisl6
andauthored
add service_lib and aar to the docs (#2634)
* add service_lib and aar to the docs * Update doc/source/quickstart.rst Co-authored-by: Mirko Galimberti <[email protected]> * Update doc/source/buildoptions.rst Co-authored-by: Mirko Galimberti <[email protected]> * add PATH_TO_SERVICE_PY * Update doc/source/services.rst Co-authored-by: Mirko Galimberti <[email protected]> Co-authored-by: Mirko Galimberti <[email protected]>
1 parent 73539bf commit cae8a85

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

doc/source/buildoptions.rst

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ Python versions
1111
python-for-android supports using Python 3.7 or higher. To explicitly select a Python
1212
version in your requirements, use e.g. ``--requirements=python3==3.7.1,hostpython3==3.7.1``.
1313

14-
The last python-for-android version supporting Python2 was `v2019.10.06
15-
<https://github.com/kivy/python-for-android/archive/v2019.10.06.zip>`__
14+
The last python-for-android version supporting Python2 was `v2019.10.06 <https://github.com/kivy/python-for-android/archive/v2019.10.06.zip>`__
1615

1716
Python-for-android no longer supports building for Python 3 using the CrystaX
18-
NDK. The last python-for-android version supporting CrystaX was `0.7.0.
19-
<https://github.com/kivy/python-for-android/archive/0.7.0.zip>`__
17+
NDK. The last python-for-android version supporting CrystaX was `0.7.0 <https://github.com/kivy/python-for-android/archive/0.7.0.zip>`__
2018

2119
.. _bootstrap_build_options:
2220

@@ -156,47 +154,29 @@ ready.
156154
access. Defaults to 5000.
157155

158156

159-
Build options
160-
%%%%%%%%%%%%%
157+
service_library
158+
~~~~~~~~~~~~~~~
161159

162-
The sdl2 bootstrap supports the following additional command line
163-
options (this list may not be exhaustive):
160+
You can use this with ``--bootstrap=service_library`` option.
161+
162+
163+
This bootstrap can be used together with ``aar`` output target to generate
164+
a library, containing Python services that can be used with other build
165+
systems and frameworks.
164166

165167
- ``--private``: The directory containing your project files.
166-
- ``--dir``: The directory containing your project files if you want
167-
them to be unpacked to the external storage directory rather than
168-
the app private directory.
169168
- ``--package``: The Java package name for your project. e.g. ``org.example.yourapp``.
170-
- ``--name``: The app name.
169+
- ``--name``: The library name.
171170
- ``--version``: The version number.
172-
- ``--orientation``: One of ``portait``, ``landscape`` or ``sensor``
173-
to automatically rotate according to the device orientation.
174-
- ``--icon``: A path to the png file to use as the application icon.
175-
- ``--ignore-path``: A path to ignore when including the app
176-
files. Pass multiple times to ignore multiple paths.
177-
- ``-- permission``: A permission name for the app,
178-
e.g. ``--permission VIBRATE``. For multiple permissions, add
179-
multiple ``--permission`` arguments.
180-
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
181-
- ``--presplash``: A path to the image file to use as a screen while
182-
the application is loading.
183-
- ``--wakelock``: If the argument is included, the application will
184-
prevent the device from sleeping.
185-
- ``--window``: If the argument is included, the application will not
186-
cover the Android status bar.
171+
- ``--service``: A service name and the Python script it should
172+
run. See :ref:`arbitrary_scripts_services`.
187173
- ``--blacklist``: The path to a file containing blacklisted patterns
188-
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
174+
that will be excluded from the final AAR. Defaults to ``./blacklist.txt``.
189175
- ``--whitelist``: The path to a file containing whitelisted patterns
190-
that will be included in the APK even if also blacklisted.
176+
that will be included in the AAR even if also blacklisted.
191177
- ``--add-jar``: The path to a .jar file to include in the APK. To
192178
include multiple jar files, pass this argument multiple times.
193-
- ``--intent-filters``: A file path containing intent filter xml to be
194-
included in AndroidManifest.xml.
195-
- ``--service``: A service name and the Python script it should
196-
run. See :ref:`arbitrary_scripts_services`.
197179
- ``add-source``: Add a source directory to the app's Java code.
198-
- ``--compile-pyo``: Optimise .py files to .pyo.
199-
- ``--resource``: A key=value pair to add in the string.xml resource file.
200180

201181

202182
Requirements blacklist (APK size optimization)

doc/source/quickstart.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Concepts
2626

2727
- **bootstrap:** A bootstrap is the app backend that will start your
2828
application. The default for graphical applications is SDL2.
29-
You can also use e.g. the webview for web apps, or service_only for
29+
You can also use e.g. the webview for web apps, or service_only/service_library for
3030
background services. Different bootstraps have different additional
3131
build options.
3232

@@ -213,6 +213,19 @@ You can also replace flask with another web framework.
213213
Replace ``--port=5000`` with the port on which your app will serve a
214214
website. The default for Flask is 5000.
215215

216+
217+
Build a Service library archive
218+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219+
220+
To build an android archive (.aar), containing an android service , you need a name, version, package identifier, explicitly use the
221+
service_library bootstrap, and declare service entry point (See :ref:`services <arbitrary_scripts_services>` for more options), as well as the requirements and arch(s)::
222+
223+
p4a aar --private $HOME/code/myapp --package=org.example.myapp --name "My library" --version 0.1 --bootstrap=service_library --requirements=python3 --release --service=myservice:service.py --arch=arm64-v8a --arch=armeabi-v7a
224+
225+
226+
You can then call the generated Java entrypoint(s) for your Python service(s) in other apk build frameworks.
227+
228+
216229
Exporting the Android App Bundle (aab) for distributing it on Google Play
217230
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218231

doc/source/services.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,23 @@ more flexible, supporting multiple services and a wider range of
5252
options.
5353

5454
To create the service, create a python script with your service code
55-
and add a :code:`--service=myservice:/path/to/myservice.py` argument
55+
and add a :code:`--service=myservice:PATH_TO_SERVICE_PY` argument
5656
when calling python-for-android, or in buildozer.spec, a
57-
:code:`services = myservice:/path/to/myservice.py` [app] setting.
57+
:code:`services = myservice:PATH_TO_SERVICE_PY` [app] setting.
58+
5859
The ``myservice`` name before the colon is the name of the service
59-
class, via which you will interact with it later. You can add multiple
60+
class, via which you will interact with it later.
61+
62+
The ``PATH_TO_SERVICE_PY`` is the relative path to the service entry point (like ``services/myservice.py``)
63+
64+
You can optionally specify the following parameters:
65+
- :code:`:foreground` for launching a service as an Android foreground service
66+
- :code:`:sticky` for launching a service that gets restarted by the Android OS on exit/error
67+
68+
Full command with all the optional parameters included would be:
69+
:code:`--service=myservice:services/myservice.py:foreground:sticky`
70+
71+
You can add multiple
6072
:code:`--service` arguments to include multiple services, or separate
6173
them with a comma in buildozer.spec, all of which you will later be
6274
able to stop and start from your app.

0 commit comments

Comments
 (0)