Skip to content

Commit e2e99eb

Browse files
committed
- updating to Qt 6.8.0
1 parent 391ca93 commit e2e99eb

File tree

1 file changed

+244
-106
lines changed

1 file changed

+244
-106
lines changed

README.md

Lines changed: 244 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,253 @@
33
> DISCLAIMER: This guide is unofficial and not affiliated with Qt. Please refer to the Official Documentation about the compiling process for Android.
44
55
[Taking Qt for Python to Android](https://www.qt.io/blog/taking-qt-for-python-to-android)
6+
<br>[Qt for Python v6.8](https://www.qt.io/blog/qt-for-python-release-6.8)
7+
8+
## **This Guide is up to date with version:**
9+
10+
`PySide6 == 6.8.0`
11+
12+
## Table of contents
13+
- [General](#a-general-explanation)
14+
- [Downloading the Android wheels](#downloading-the-android-wheels)
15+
- [Setup](#setup)
16+
- [Building the Android APK](#building-the-android-apk)
17+
- [PySide6 modification](#pyside6-modification)
18+
- [The final build process](#the-final-build-process)
19+
- [Installation of your App](#installation-best-practices)
20+
- [Errors and solutions](#errors-and-potential-solutions)
21+
- RuntimeError
22+
- C-Compiler can not create executables
23+
- python package architecture mismatch
24+
- DeadObjectException
25+
- [Building the Wheels (LEGACY)](#legacy-building-the-wheels)
26+
- [Install dependencies](#install-dependencies)
27+
- [PySide-Setup](#pyside-setup)
28+
- [Building the wheels](#building-the-qt-wheels)
29+
630

731
> [!WARNING]
8-
> My own compiled Android application has some serious UI issues (when scrolling, and crashes). I don't know where this comes from.
9-
> If you experience this too, don't worry, I am actively searching for a solution, and you aren't alone.
32+
> Before proceeding, make sure your app is compatible with either `Python3.10.x` or `Python3.11.x`
33+
34+
# A general explanation
35+
36+
Android devices can have one of the four architectures: `armv7`, `aarch64`, `x86_64`, `i686`.
37+
You should compile your application for all four of these. This involves using the official `pyside6-android-deploy`
38+
tool, which will automatically sets everything up.
39+
40+
## Downloading the Android wheels
41+
42+
Since Qt Version `6.8` Qt published their own Android wheels, which you need for building. I **STRONGLY**
43+
recommend you to download them, instead of compiling your own.
44+
45+
However, if you want to compile them by yourself, you can skip to the [LEGACY](#legacy-building-the-wheels) part.
46+
47+
Here's the link to their public archive: `https://download.qt.io/official_releases/QtForPython/pyside6/`
48+
49+
And here are the links for every release:
50+
> [!NOTE]
51+
> Only the `aarch64` and `x86_64` versions are available at the moment.
52+
53+
I also compile my own wheels, which you can download in the release repository, although
54+
there's no guarantee for them to work!
55+
56+
- [PySide6 - aarch64](https://download.qt.io/official_releases/QtForPython/pyside6/PySide6-6.8.0-6.8.0-cp311-cp311-android_aarch64.whl)
57+
- ~~[PySide6 - armv7]()~~
58+
- ~~[PySide6 - i686]()~~
59+
- [PySide6 - x86_64](https://download.qt.io/official_releases/QtForPython/pyside6/PySide6-6.8.0-6.8.0-cp311-cp311-android_x86_64.whl)
60+
61+
- [Shiboken - aarch64](https://download.qt.io/official_releases/QtForPython/pyside6/shiboken6-6.8.0-6.8.0-cp311-cp311-android_aarch64.whl)
62+
- ~~[Shiboken - armv7]()~~
63+
- ~~[Shiboken - i686]()~~
64+
- [Shiboken - x86_64](https://download.qt.io/official_releases/QtForPython/pyside6/shiboken6-6.8.0-6.8.0-cp311-cp311-android_x86_64.whl)
65+
66+
# Setup
67+
When building the .apk you need the Android SDK and NDK. You can install them manually and skip this
68+
section, but to make your life a little bit easier, I recommend using Qt's own tool for that purpose.
69+
70+
**Dependencies:**
71+
72+
Although you do not need all of them, I recommend installing them:
73+
74+
```bash
75+
sudo pacman -Syu base-devel android-tools android-udev clang jdk17-openjdk llvm openssl cmake wget git
76+
```
77+
78+
79+
```bash
80+
cd ~/
81+
git clone https://code.qt.io/pyside/pyside-setup
82+
cd pyside-setup
83+
git checkout 6.8.0
84+
python3 -m venv venv
85+
source venv/bin/activate
86+
pip install -r requirements.txt
87+
pip install -r tools/cross_compile_android/requirements.txt
88+
python tools/cross_compile_android/main.py --download-only --verbose
89+
```
90+
91+
> [!IMPORTANT]
92+
> Make sure to use the --verbose flag, otherwise it won't show you the License Agreement for the SDK
93+
> and you won't be able to install the build tools.
94+
95+
96+
After you are finished with this your Android SDK and NDK are in the following directories:
97+
98+
Android SDK: `~/.pyside6_android_deploy/android-sdk`
99+
<br>Android NDK: `~/.pyside6_android_deploy/android-ndk/android-ndk-r26b/`
100+
101+
# Building the Android APK
102+
103+
# The `buildozer.spec` file
104+
> [!NOTE]
105+
> Although you do not need this for a base PySide6 application, I still recommend you to
106+
> read through the following part, because it contains very important things for your Android App.
107+
108+
Buildozer is the tool which generates the .apk file using P4A (Python for Android) as backend.
109+
The buildozer.spec file is a configuration file which is generated on Buildozer's first run.
110+
It's used to configure the behaviour of your application. For example whether your App should
111+
run in portrait or landscape mode and other things. Here's a list of the most important options:
112+
113+
- `requirements`: The list of all python packages used in your app See [Buildozer.spec](#the-buildozerspec-file)
114+
- `icon.filename`: The Icon of your App as a .png or .jpg. Please have a look at Google's [Adaptive Icons](https://developer.android.com/develop/ui/views/launch/icon_design_adaptive?hl=de)
115+
- `title`: Your App name
116+
- `version`: The version of your application e.g, 1.1
117+
- `android.permissions:` All permissions your App needs. Have a look at [Android Permissions](https://developer.android.com/reference/android/Manifest.permission.html)
118+
- `package.name`: The name of your package, which is the output of buildozer
119+
- `package.domain`: The unique identifier of your app inside the Android app system
120+
- `orientation`: The orientation of your app: `portrait` ->: `||` or `landscape` ->: `===`
121+
122+
#### Special Note on `charset_normalizer` and `requests`:
123+
If your project uses the 'requests' library or any other library dependent on 'charset_normalizer', ensure to specify
124+
the version `charset-normalizer==2.1.1` in your requirements, otherwise there will be an architecture
125+
mismatch.
126+
127+
128+
### PySide6 modification
129+
Unfortunately the `pyside6-android-deploy` script starts the build proces immediately, without giving
130+
you the option to manually review the buildozer.spec file, which is the reason why we need to do
131+
a little modification, but don't worry it's easy:
132+
133+
1) Go into your virtual environment to the PySide6 folder (e.g: venv/lib/python3.11/site-packages/PySide6/scripts/)
134+
2) Edit the `android_deploy.py` file.
135+
3) Search for the line: `logging.info("[DEPLOY] Running buildozer deployment")`
136+
4) Above this line write this: `input("Modify your buildozer.spec now")`
137+
10138

11-
# Building the Qt for Python Wheels
139+
When you start building the apk with `pyside6-android-deploy` the build process will stop at some point,
140+
and then you can make adjustments to the `buildozer.spec` file. After you are done, just press enter
141+
the build process, and it will go on using your own options in the requirements.
142+
143+
# The final build process
12144
> [!IMPORTANT]
13-
> You can use the pre-compiled Wheels in the Repository's release. If they don't work, you need to compile them
14-
> You will however still need to set up your Android SDK / NDK, so that it works for buildozer.
145+
> Make sure your script is named `main.py`
146+
147+
Go into your source directory and type the following:
148+
149+
`pyside6-android-deploy --wheel-pyside=<your .whl file for the architecture> --wheel-shiboken=<your .whl file for your architecture> --name=main --ndk-path ~/.pyside6_android_deploy/android-ndk/android-ndk-r26b --sdk-path ~/.pyside6_android_deploy/android-sdk/
150+
151+
#### Explanation:
152+
- --wheel-pyside= Here comes your PySide6 wheel which you've downloaded or compiled
153+
- --wheel-shiboken= Here comes your Shiboken wheel which you've downloaded or compiled
154+
- --name= The name of your application
155+
- --ndk-path= The path to your Android NDK (See [Setup](#setup))
156+
- --sdk-path= The path to your Android SDK (See [Setup](#setup))
157+
158+
159+
The script will start configuring buildozer and buildozer will start the build process.
160+
At the end you will have a .apk file for the specified Android architecture.
161+
162+
### Installation (Best practices)
163+
164+
I generally recommend you to use ADB / Fastboot to install, and debug your Android application.
165+
Once you understood how it works, it makes your life a lot easier...
166+
167+
1. Go into your system information and tap a few times on your build number
168+
2. Go (or search) into the developer settings
169+
3. Enable USB-Debugging (Or Debugging over W-Lan, but this is a little bit advanced)
170+
4. Install the android-tools on your system:
171+
- On Arch Linux: `sudo pacman -S android-tools`
172+
- On Ubuntu: `sudo apt install android-tools-adb android-tools-fastboot`
173+
- On Windows: `Imagine using Windows lol`
174+
175+
5. Type: `adb devices`
176+
6. On your device there should be a popup asking for your permission. Click on confirm.
177+
7. Type: `adb devices` once again and confirm, that you see your device there.
178+
179+
The two magical commands
15180

16-
### Current Release: 6.7.1
17-
- Python3.11: [Qt 6.7.1](https://github.com/EchterAlsFake/PySide6-to-Android/releases/tag/6.7.1_3.11)
181+
Install your apk: `adb install <path_to_apk_file>`
182+
<br>Debug your app: `adb logcat --regex "<package.domain>`
183+
184+
After your apk was installed, you will see it in your system apps. Click on your app,
185+
scroll down and at the very last line it should say something like:
186+
187+
```
188+
Version 2.1.6
189+
com.digibites.accubattery
190+
```
191+
192+
The first line is your App version and the second line is your package domain.
193+
<br>After executing the logcat command, you can start your App and you should see a lot
194+
of debug messages. In case your app crashes, you can see what went wrong, although the crash
195+
report isn't always very helpful...
196+
197+
> [!NOTE]
198+
> These instructions are based on my Pixel 7 Pro running Android 14. The steps for you might
199+
> be different, but in general they are all very similar on all Android devices. If you are
200+
> stuck somewhere, XDA, Google and StackOverflow are your best friends :D
201+
202+
203+
204+
# Errors and (potential) solutions:
205+
- RuntimeError: "You are including a lot of QML files from a local venv..."
206+
This error is related to your virtual environment. Make sure your virtual environment
207+
is NOT inside your projects' folder. It doesn't matter where it is, but must not be in your projects'
208+
folder. For example, if you have your main.py in a folder named my_project, then your
209+
virtual environment can't be in this folder!
210+
<br>
211+
Create a new virtual environment in a different location and delete your old one with
212+
`rm -rf venv .venv` (or whatever you've called it)
213+
<br>
214+
This is more an issue from Qt and will hopefully be fixed in a later Qt release, so that
215+
you don't need to do this anymore. I know it's confusing.
216+
217+
- c compiler can not create executables
218+
Don't worry, this issue most of the time comes because you are using a too high API level. Just go into the path, where it
219+
says the C compiler wouldn't be able to create executables and then look inside this directory. You'll find files ending like
220+
`androidclang33-` (or something like that). The highest number which is there is the highest number you can select.
221+
222+
- blah blash blah is for x86_64 architecture not aarch64
223+
<br>Solution: Search online if the pip package has a verified aarch64 version. If it doesn't prepare for some months of work
224+
building the recipes lmao
225+
226+
- DeadObjectException (Couldn't insert ... into...)
227+
<br>Solution: Could be anything. but possibly one of your imported packages has an issue such as not
228+
being available. If you are sure that this is not the case, I would suggest you to make a basic
229+
test application which just shows a window and a test label, and you try to import one package by one
230+
until it breaks.
231+
232+
> [!IMPORTANT]
233+
> I AGAIN want to remind you of using the Java version 17! Java 11 is supported by Gradle and even recommended, but not
234+
> supported by Qt, and version 21 is supported by Qt, but not by the currently used Gradle version. This may change in the
235+
> future and I will update it accordingly.
236+
237+
# Contributions / Issues
238+
If you see Issues in this guide, or you have something to improve it, feel free to open PRs and Issues. I'll
239+
respond to them and try to help you as much as possible. (Only for Arch Linux).
240+
241+
Maybe someone of you can make an alternative readme for other distros. Would be nice :)
242+
243+
# Support
244+
I appreciate every star on this repo, as it shows me that my work is useful for people, and it keeps me motivated :)
245+
246+
247+
# Legacy (Building the wheels)
248+
249+
> [!NOTE]
250+
> Please note, that this won't be maintained as often and that the following part is NOT perfect
251+
> and may contain some issues. This is made to get you into the right direction, but shouldn't be
252+
> seen as a perfect tutorial or guide!
18253
19254

20255
## Installing Qt
@@ -42,6 +277,7 @@ Explanation:
42277
This is the source directory of PySide6. Just execute the bash stuff below. It will install the needed stuff. Execute this one time
43278
and REMEMBER where you've cloned this to, as we need this later :)
44279

280+
45281
```bash
46282
python -m venv venv # Needed, trust me...
47283
source venv/bin/activate
@@ -57,7 +293,7 @@ elif [ -n "$BASH_VERSION" ]; then
57293
fi
58294

59295
cd pyside-setup
60-
git checkout 6.7.2
296+
git checkout 6.8.0
61297
pip install -r requirements.txt
62298
pip install -r tools/cross_compile_android/requirements.txt
63299
pip install pyside6
@@ -112,101 +348,3 @@ Now, execute this command for all 4 Android architectures.
112348
Your Wheels should be in the `dist` folder at the end.
113349

114350
If you get any errors, try to use the `--clean-cache all` argument first.
115-
116-
# Building the Android APK
117-
118-
## PySide6 modification (Important)
119-
> [!IMPORTANT]
120-
> If your project depends on external libraries other than PySide6, you need to do the following steps:
121-
122-
1) Go into your virtual environment to the PySide6 folder (e.g: venv/lib/python3.11/site-packages/PySide6/scripts/)
123-
2) Edit the `android_deploy.py` file.
124-
3) Search for the line: `logging.info("[DEPLOY] Running buildozer deployment")`
125-
4) Above this line write this: `input("Modify your buildozer.spec now")`
126-
127-
Done :)
128-
129-
Explanation:
130-
131-
Later, when buildozer builds your .apk the `buildozer.spec` file will be created. It defines a lot of things, and also
132-
which external libraries are used. Unfortunately the pyside6-android-deploy script doesn't let you edit this file, which
133-
is the reason why we need to make an input statement, so that you can write your external libraries in their, before it
134-
gets processed. (Sidenote: it took me 6 months to figure this out :skull:)
135-
136-
# Building the APK
137-
The wheels are in pyside-setup/dist/ (Or use the downloaded ones from releases)
138-
```pyside6-android-deploy --wheel-pyside=<your .whl file for the architecture> --wheel-shiboken=<your .whl file for your architecture> --name=main --ndk-path ~/.pyside6_android_deploy/android-ndk/android-ndk-r26b --sdk-path ~/.pyside6_android_deploy/android-sdk/```
139-
140-
> [!NOTE]
141-
> If you've changed your NDK version, you of course need to adapt the path to your NDK version.
142-
143-
### Other Stuff (Important)
144-
145-
#### pysidedeploy.spec
146-
147-
The `pysidedeploy.spec` file is used to define your Application name, the architecture and some other things.
148-
The `pysidedeploy.spec` file is created when you build your first .apk. You can use this file by doing:
149-
150-
`pyside6-android-deploy -c pysidedeploy.spec` This makes the process easier.
151-
152-
#### External Libraries
153-
If your App needs external libraries like requests or colorama, you need to list them in the
154-
`requirements` line (in the buildozer.spec). Just separate them with a comma.
155-
You can specify exact version numbers like with pip and also install from git using `git+....`
156-
157-
#### App Icon
158-
If you want to use your own App Icon you can do:
159-
<br>
160-
`icon.filename = <path_to_your_app_icon_png>`
161-
162-
# Debugging / Error finding
163-
164-
I HIGHLY recommend to download the Android studio and run your App from the Android Studio.
165-
Just connect your Phone or Tablet to your PC, enable USB Debugging and start your App from the Android
166-
Studio, because this will allow you to easily profile and debug your apk. You will see all Python tracebacks, and it makes
167-
it a lot easier to debug.
168-
169-
## Special Note on 'charset_normalizer'
170-
If your project uses the 'requests' library or any other library dependent on 'charset_normalizer', ensure to specify the version `charset-normalizer==2.1.1` in your requirements.
171-
172-
# Storage Permissions
173-
Kivy and Pyjnius don't work. We can't access the Java API on Android and therefore can't request Permissions at runtime.
174-
You need to use a lower Android API to ue the legacy storage paths in /storage/emulated/0/...
175-
176-
177-
# Errors:
178-
- RuntimeError: "You are including a lot of QML files from a local venv..."
179-
180-
This error is related to your virtual environment. Make sure your virtual environment
181-
is NOT inside your projects' folder. It doesn't matter where it is, but must not be in your projects'
182-
folder. For example, if you have your main.py in a folder named my_project, then your
183-
virtual environment can't be in this folder!
184-
185-
Create a new virtual environment in a different location and delete your old one with
186-
`rm -rf venv .venv` (or whatever you've called it)
187-
188-
This is more an issue from Qt and will hopefully be fixed in a later Qt release, so that
189-
you don't need to do this anymore. I know it's confusing.
190-
191-
- c compiler can not create executables
192-
Don't worry, this issue most of the time comes because you are using a too high API level. Just go into the path, where it
193-
says the C compiler wouldn't be able to create executables and then look inside this directory. You'll find files ending like
194-
`androidclang33-` (or something like that). The highest number which is there is the highest number you can select.
195-
196-
- blah blash blah is for x86_64 architecture not aarch64
197-
<br>Solution: Search online if the pip package has a verified aarch64 version. If it doesn't prepare for some months of work
198-
building the receipes lmao
199-
200-
> [!IMPORTANT]
201-
> I AGAIN want to remind you of using the Java version 17! Java 11 is supported by Gradle and even recommended, but not
202-
> supported by Qt, and version 21 is supported by Qt, but not by the currently used Gradle version. This may change in the
203-
> future and I will update it accordingly.
204-
205-
# Contributions / Issues
206-
If you see Issues in this guide, or you have something to improve it, feel free to open PRs and Issues. I'll
207-
respond to them and try to help you as much as possible. (Only for Arch Linux).
208-
209-
Maybe someone of you can make an alternative readme for other distros. Would be nice :)
210-
211-
# Support
212-
I appreciate every star on this repo, as it shows me that my work is useful for people, and it keeps me motivated :)

0 commit comments

Comments
 (0)