Skip to content

Commit 0ea77ce

Browse files
committed
Refactor Android build workflow and update dependencies in buildozer.spec
1 parent fdb29cb commit 0ea77ce

File tree

4 files changed

+151
-44
lines changed

4 files changed

+151
-44
lines changed

.github/workflows/android.build.yml

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,37 @@ jobs:
4545
restore-keys: |
4646
${{ runner.os }}-buildozer-
4747
48-
- name: Install Buildozer dependencies
48+
- name: Install Buildozer system dependencies
4949
run: |
5050
sudo apt-get update
5151
sudo apt-get install -y \
52-
git \
53-
zip \
54-
unzip \
55-
build-essential \
56-
python3-pip \
57-
python3-dev \
58-
libffi-dev \
59-
libssl-dev \
60-
libncurses5-dev \
61-
zlib1g-dev \
62-
libsqlite3-dev \
63-
libbz2-dev \
64-
autoconf \
65-
automake \
66-
libtool \
67-
cython3 \
68-
ccache # Recommended by Buildozer for faster C builds
52+
git zip unzip build-essential python3-pip python3-dev \
53+
libffi-dev libssl-dev libncurses5-dev zlib1g-dev libsqlite3-dev libbz2-dev \
54+
autoconf automake libtool pkg-config \ # Ensure pkg-config is installed
55+
cython3 ccache
6956
70-
71-
- name: Install Buildozer and dependencies from spec
57+
- name: Install Python build tools and Cython
7258
run: |
7359
python -m pip install --upgrade pip wheel setuptools
74-
python -m pip install buildozer cython # Install buildozer and cython
75-
# Consider installing python requirements here if needed before buildozer runs
76-
# python -m pip install -r requirements.txt # If you have one
60+
python -m pip install cython
61+
62+
- name: Install Buildozer
63+
run: |
64+
python -m pip install buildozer
65+
python -m pip install -r requirements.kivy.txt
7766
67+
68+
7869
- name: Build APK with Buildozer
70+
# Set ACLOCAL_PATH and PKG_CONFIG_PATH explicitly before running buildozer
71+
# This helps autotools find necessary macro and package config files
7972
run: |
73+
export ACLOCAL_PATH="${ACLOCAL_PATH}:/usr/share/aclocal"
74+
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig"
8075
buildozer -v android debug # Change to 'release' for release builds
81-
76+
8277
- name: Upload APK artifact
8378
uses: actions/upload-artifact@v4
8479
with:
85-
name: fiscalberry-android-apk-${{ github.ref_name }} # More descriptive name
86-
path: bin/*.apk # Path where Buildozer places the APK
80+
name: fiscalberry-android-apk-${{ github.ref_name }}
81+
path: bin/*.apk

.github/workflows/desktop.build.yml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ jobs:
2727
python_platform: win32
2828
- os: macos-latest
2929
os_name: macos
30-
asset_suffix_cli: mac-x64 # Adjust if building universal/arm64
31-
asset_suffix_gui: gui-mac-x64 # Adjust if building universal/arm64
30+
asset_suffix_cli: mac-x64
31+
asset_suffix_gui: mac-x64.app
3232
artifact_path_cli: dist/fiscalberry-cli
33-
artifact_path_gui: dist/fiscalberry-gui
34-
python_platform: darwin # sys.platform value for macOS
33+
artifact_path_gui: dist/fiscalberry-gui.app
34+
python_platform: darwin
3535

3636
runs-on: ${{ matrix.os }}
3737

@@ -86,18 +86,7 @@ jobs:
8686
- name: Rename GUI artifact
8787
shell: bash # Use bash for consistent mv/move commands
8888
run: |
89-
mv ${{ matrix.artifact_path_gui }} artifacts/fiscalberry-gui-${{ matrix.asset_suffix_gui }}
90-
91-
# --- Build GUI ---
92-
- name: Install GUI dependencies (includes Kivy)
93-
run: pip install -r requirements.kivy.txt # This should include CLI deps too
94-
95-
- name: Build GUI executable (${{ matrix.os_name }})
96-
run: pyinstaller fiscalberry-gui.spec
97-
98-
- name: Rename GUI artifact
99-
shell: bash # Use bash for consistent mv/move commands
100-
run: |
89+
mkdir -p artifacts
10190
mv ${{ matrix.artifact_path_gui }} artifacts/fiscalberry-gui-${{ matrix.asset_suffix_gui }}
10291
10392
- name: Upload executables artifact (${{ matrix.os_name }})
@@ -134,7 +123,7 @@ jobs:
134123
- name: Rename Pi CLI artifact
135124
run: |
136125
mkdir -p artifacts
137-
mv dist/fiscalberry-pi artifacts/fiscalberry-cli-pi-arm64
126+
mv dist/fiscalberry-cli artifacts/fiscalberry-cli-pi-arm64
138127
139128
- name: Upload Pi CLI executable artifact
140129
uses: actions/upload-artifact@v4

buildozer.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ version.filename = %(source.dir)s/fiscalberry/__init__.py
4242
# Comma-separated list of recipes or pure-Python packages.
4343
# IMPORTANT: Verify each requirement. Check if python-for-android recipes exist for non-pure-Python libs.
4444
# Remove unnecessary dependencies (like pika if not used on mobile, pywin32, argparse).
45-
requirements = hostpython3,python3,kivy==2.3.0,python-escpos,python-socketio[client],requests,aiohttp,pillow,python-barcode[images],qrcode[pil],uuid,appdirs,platformdirs,pyjnius
45+
requirements = hostpython3,python3,kivy==2.3.0,python-escpos,python-socketio[client],requests,aiohttp,pillow,python-barcode[images],qrcode[pil],appdirs,platformdirs,pyjnius
4646
4747
# (str) Presplash of the application
4848
presplash.filename = %(source.dir)s/fiscalberry/ui/assets/fiscalberry.png

src/fiscalberryservice/android.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
from time import sleep
2+
import os
3+
from jnius import autoclass
4+
5+
# -*- coding: utf-8 -*-
6+
7+
"""
8+
Basic structure for an Android background service using Python.
9+
This typically requires a framework like Kivy (with python-for-android)
10+
or Chaquopy to bridge Python with the Android OS.
11+
"""
12+
13+
14+
# Using jnius (common with Kivy/python-for-android) to interact with Android APIs
15+
try:
16+
# Example: Get access to the service context if running under PythonService
17+
# PythonService = autoclass('org.kivy.android.PythonService')
18+
# service = PythonService.mService
19+
pass
20+
except ImportError:
21+
print("jnius not found. Android-specific features may not work.")
22+
autoclass = None
23+
service = None
24+
25+
def run_service_logic():
26+
"""Contains the main logic for the background service."""
27+
print("Android Service: Starting background logic.")
28+
29+
# Example: Retrieve an argument passed when starting the service
30+
# This environment variable is often set by the service starter (e.g., Kivy's PythonService)
31+
service_argument = os.environ.get('PYTHON_SERVICE_ARGUMENT', 'No argument provided')
32+
print(f"Android Service: Received argument: {service_argument}")
33+
34+
# Main service loop
35+
counter = 0
36+
while True:
37+
print(f"Android Service: Running... Loop count: {counter}")
38+
39+
# --- Add your background tasks here ---
40+
# Examples:
41+
# - Polling a server for updates
42+
# - Processing data in the background
43+
# - Interacting with hardware (requires specific permissions and APIs)
44+
# - Sending notifications (requires Android API calls via jnius/plyer)
45+
46+
# Example: Show a Toast notification (requires context and jnius)
47+
# if autoclass and service:
48+
# try:
49+
# Toast = autoclass('android.widget.Toast')
50+
# CharSequence = autoclass('java.lang.CharSequence')
51+
# context = service.getApplicationContext()
52+
# if context:
53+
# def show_toast():
54+
# text = CharSequence(f"Service running {counter}")
55+
# toast = Toast.makeText(context, text, Toast.LENGTH_SHORT)
56+
# toast.show()
57+
# # Toasts must be shown on the UI thread
58+
# PythonActivity = autoclass('org.kivy.android.PythonActivity')
59+
# PythonActivity.mActivity.runOnUiThread(show_toast)
60+
# except Exception as e:
61+
# print(f"Android Service: Error showing toast - {e}")
62+
63+
# Sleep for a period before the next iteration
64+
sleep(15) # Sleep for 15 seconds
65+
counter += 1
66+
67+
# Add conditions to stop the service if necessary,
68+
# although services are often designed to run until explicitly stopped.
69+
# For example:
70+
# if should_stop_service():
71+
# print("Android Service: Stopping condition met.")
72+
# break
73+
74+
print("Android Service: Background logic finished.")
75+
76+
if __name__ == "__main__":
77+
# This block is executed when the script is run directly.
78+
# When launched as an Android service by the framework (e.g., Kivy),
79+
# the framework typically imports and runs this script, potentially
80+
# calling a specific function or just executing the module level code.
81+
# The `run_service_logic()` function contains the core tasks.
82+
run_service_logic()
83+
84+
# --- Notes on Deployment as an Android Service ---
85+
#
86+
# 1. **Framework:** Use Kivy (with buildozer) or Chaquopy.
87+
# 2. **Configuration (Buildozer Example):**
88+
# In `buildozer.spec`, define the service:
89+
# ```
90+
# services = YourServiceName:./src/fiscalberryservice/android.py
91+
# ```
92+
# Replace `YourServiceName` and adjust the path.
93+
# 3. **Starting the Service:**
94+
# Start it from your main app (e.g., Kivy `main.py`) using Android Intents via jnius:
95+
# ```python
96+
# from jnius import autoclass
97+
# import os
98+
#
99+
# PythonActivity = autoclass('org.kivy.android.PythonActivity')
100+
# activity = PythonActivity.mActivity
101+
# Intent = autoclass('android.content.Intent')
102+
#
103+
# service_name = 'YourServiceName' # Must match buildozer.spec
104+
# service_class_name = f'{activity.getPackageName()}.Service{service_name}'
105+
#
106+
# intent = Intent()
107+
# intent.setClassName(activity, service_class_name)
108+
#
109+
# # Pass data to the service (optional)
110+
# argument = "Data for the service"
111+
# intent.putExtra('PYTHON_SERVICE_ARGUMENT', argument)
112+
# os.environ['PYTHON_SERVICE_ARGUMENT'] = argument # Set env var too
113+
#
114+
# activity.startService(intent)
115+
# ```
116+
# 4. **Permissions:** Add necessary permissions to `buildozer.spec`:
117+
# ```
118+
# android.permissions = INTERNET, FOREGROUND_SERVICE, ...
119+
# ```
120+
# `FOREGROUND_SERVICE` is often required for long-running tasks on newer Android versions.
121+
# 5. **Foreground Service:** For long-running tasks, consider running as a foreground service
122+
# to prevent Android from killing it. This requires showing a persistent notification.
123+
# You'll need more jnius code to create the notification channel and notification itself.

0 commit comments

Comments
 (0)