mirror of
https://github.com/NaitLee/Cat-Printer.git
synced 2025-05-15 23:00:15 -07:00
Modifications to android build doc and scripts
This commit is contained in:
parent
467857e542
commit
85cb5a86cb
22
build-android/.p4a
Normal file
22
build-android/.p4a
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
--private ..
|
||||||
|
--dist_name "cat-printer"
|
||||||
|
--package "io.github.naitlee.catprinter"
|
||||||
|
--name "Cat Printer"
|
||||||
|
--icon icon.png
|
||||||
|
--bootstrap webview
|
||||||
|
--window
|
||||||
|
--blacklist-requirements sqlite3,openssl
|
||||||
|
--port 8095
|
||||||
|
--arch arm64-v8a
|
||||||
|
--blacklist "blacklist.txt"
|
||||||
|
--presplash blank.png
|
||||||
|
--presplash-color black
|
||||||
|
--add-source "advancedwebview"
|
||||||
|
--manifest-orientation user
|
||||||
|
--android_api 30
|
||||||
|
--permission BLUETOOTH
|
||||||
|
--permission BLUETOOTH_SCAN
|
||||||
|
--permission BLUETOOTH_CONNECT
|
||||||
|
--permission BLUETOOTH_ADMIN
|
||||||
|
--permission ACCESS_FINE_LOCATION
|
||||||
|
--permission ACCESS_COARSE_LOCATION
|
@ -1,9 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
version=`cat ../version`
|
version=`cat ../version`
|
||||||
|
|
||||||
p4a apk --private .. --dist_name="cat-printer" --package="io.github.naitlee.catprinter" --name="Cat Printer" \
|
p4a apk --requirements "`cat build-deps.txt`" --version "$version" $@
|
||||||
--icon=icon.png --version=$version --bootstrap=webview --window --requirements="`cat build-deps.txt`" \
|
|
||||||
--blacklist-requirements=sqlite3,openssl --port=8095 --arch=arm64-v8a --blacklist="blacklist.txt" \
|
|
||||||
--presplash=blank.png --presplash-color=black --add-source="advancedwebview" --manifest-orientation=user \
|
|
||||||
--permission=BLUETOOTH --permission=BLUETOOTH_SCAN --permission=BLUETOOTH_CONNECT \
|
|
||||||
--permission=BLUETOOTH_ADMIN --permission=ACCESS_FINE_LOCATION --permission=ACCESS_COARSE_LOCATION $@
|
|
||||||
|
@ -4,9 +4,4 @@ version=`cat ../version`
|
|||||||
rm -rf "dist"
|
rm -rf "dist"
|
||||||
unzip -q "../cat-printer-bare-$version.zip"
|
unzip -q "../cat-printer-bare-$version.zip"
|
||||||
mv "cat-printer" "dist"
|
mv "cat-printer" "dist"
|
||||||
p4a apk --private "dist" --dist_name="cat-printer" --package="io.github.naitlee.catprinter" --name="Cat Printer" \
|
p4a apk --version="$version" --requirements="`cat build-deps.txt`" --release $@
|
||||||
--icon=icon.png --version="$version" --bootstrap=webview --window --requirements="`cat build-deps.txt`" \
|
|
||||||
--blacklist-requirements=sqlite3,openssl --port=8095 --arch=arm64-v8a --release \
|
|
||||||
--presplash=blank.png --presplash-color=black --add-source="advancedwebview" --orientation=user \
|
|
||||||
--permission=BLUETOOTH --permission=BLUETOOTH_SCAN --permission=BLUETOOTH_CONNECT \
|
|
||||||
--permission=BLUETOOTH_ADMIN --permission=ACCESS_FINE_LOCATION --permission=ACCESS_COARSE_LOCATION $@
|
|
||||||
|
@ -4,7 +4,7 @@ unsigned_apk=cat-printer-release-unsigned-$version.apk
|
|||||||
signed_apk=cat-printer-android-$version.apk
|
signed_apk=cat-printer-android-$version.apk
|
||||||
|
|
||||||
if {
|
if {
|
||||||
$ANDROIDSDK/build-tools/*/zipalign 4 $unsigned_apk $signed_apk;
|
$ANDROIDSDK/build-tools/*/zipalign 4 $unsigned_apk $signed_apk &&
|
||||||
$ANDROIDSDK/build-tools/*/apksigner sign --ks $1 $signed_apk;
|
$ANDROIDSDK/build-tools/*/apksigner sign --ks $1 $signed_apk;
|
||||||
}; then
|
}; then
|
||||||
echo "Complete! Moving APK..."
|
echo "Complete! Moving APK..."
|
||||||
|
@ -5,34 +5,26 @@ Expecting to cost about half a day.
|
|||||||
|
|
||||||
Worthy to work on! This gives possibility to everything about Android in your mind!
|
Worthy to work on! This gives possibility to everything about Android in your mind!
|
||||||
|
|
||||||
|
See [#Troubleshooting](#troubleshooting) for some problems you may meet.
|
||||||
|
|
||||||
Note: not being confirmed to 100% work yet. Be the first bird to try! Or bookmark this, arrange your time & come back later.
|
Note: not being confirmed to 100% work yet. Be the first bird to try! Or bookmark this, arrange your time & come back later.
|
||||||
|
|
||||||
## Prepare
|
## Prepare
|
||||||
|
|
||||||
First, think about what will be your build environment. I choose to use a Ubuntu Docker container.
|
First, think about what will be your build environment. I choose to use a Docker container with a newer GNU/Linux distribution.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
<summary>Expand Comparison</summary>
|
<summary>Expand Notes</summary>
|
||||||
|
|
||||||
| | Minimal Ubuntu | Ubuntu | [Artix](https://artixlinux.org/) |
|
Notes:
|
||||||
| :-------------------------- | :------------: | :----: | :------: |
|
|
||||||
| Base system<sup>1</sup> | | ✓ | ✓ |
|
|
||||||
| Pkg diversity | ✓ | ✓ | ✓ |
|
|
||||||
| Fresh pkg<sup>2</sup> | | | ✓ |
|
|
||||||
| Less hassle<sup>3</sup> | ✓ | | ✓ |
|
|
||||||
| Maintainability<sup>4</sup> | ✓ | | |
|
|
||||||
|
|
||||||
Note: “Minimal Ubuntu” can mean a Ubuntu [Docker](https://docs.docker.com/get-started/overview/) image, a Ubuntu chroot environment, etc.
|
1. In theory you can just use your existing system, if you don’t afraid of messing it up.
|
||||||
|
|
||||||
1. In theory you can just have Ubuntu as base system, but see 2, 3, and 4.
|
|
||||||
2. Rolling distribution have newer packages offered.
|
2. Rolling distribution have newer packages offered.
|
||||||
It may give great experience in daily use, but will heavily bloat the update if many development packages are installed alltogether.
|
It may give great experience in daily use, but will heavily bloat the update if many development packages are installed alltogether.
|
||||||
That said, Artix alone *worked* in those days. If you want, go ahead.
|
3. By operating in an isolated environment, a mess taking place inside won’t affect the host.
|
||||||
3. Mis-designs will stress you down. systemd will ruin your mood.
|
4. Good candidates are: Arch, Artix, OpenSUSE Leap, and their neighbors.
|
||||||
4. By operating in an isolated environment, a mess taking place inside won’t affect the host.
|
5. Some say Docker isn’t intended to be “stateful”. But nothing is better in my mere knowledge.
|
||||||
|
|
||||||
(Some say Docker isn’t intended to be “stateful”. But nothing is better in my mere knowledge.)
|
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -66,7 +58,11 @@ cd $DIR_GIT
|
|||||||
# Cat-Printer
|
# Cat-Printer
|
||||||
git clone https://github.com/NaitLee/Cat-Printer.git
|
git clone https://github.com/NaitLee/Cat-Printer.git
|
||||||
# Bleak, we need some Java code from its source
|
# Bleak, we need some Java code from its source
|
||||||
git clone https://github.com/hbldh/bleak.git
|
# git clone https://github.com/hbldh/bleak.git
|
||||||
|
# Use an older version for being compatible with p4a recipes (setup.py)
|
||||||
|
wget https://files.pythonhosted.org/packages/e6/b4/e63829826a157d180831a1c5d3720e75d613c1290cb239510d148b906836/bleak-0.19.5.tar.gz
|
||||||
|
tar -xzf bleak-0.19.5.tar.gz && rm bleak-0.19.5.tar.gz
|
||||||
|
mv bleak-0.19.5 bleak
|
||||||
# AdvancedWebView, in order to give Android WebView capability to use <input type="file" />
|
# AdvancedWebView, in order to give Android WebView capability to use <input type="file" />
|
||||||
git clone https://github.com/delight-im/Android-AdvancedWebView.git
|
git clone https://github.com/delight-im/Android-AdvancedWebView.git
|
||||||
|
|
||||||
@ -83,17 +79,17 @@ After that, continue to [Fix the NDK](#fix-the-ndk).
|
|||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
If you’re in China Mainland (you guessed it!), or prefer manual setup:
|
If Google isn’t available there, or you prefer manual setup:
|
||||||
|
|
||||||
- Pick a working mirror. Currently there’s [Tencent Cloud](https://mirrors.cloud.tencent.com/AndroidSDK/).
|
- Pick a working mirror. Currently there’s [Tencent Cloud](https://mirrors.cloud.tencent.com/AndroidSDK/).
|
||||||
|
|
||||||
- Pay attention to [required version of Android NDK](https://python-for-android.readthedocs.io/en/latest/quickstart/#basic-sdk-install), this will increase by time. It’s currently r25b.
|
- Pay attention to [required version of Android NDK](https://python-for-android.readthedocs.io/en/latest/quickstart/#basic-sdk-install), this will increase by time. It’s currently r25b, but let’s use r25c.
|
||||||
|
|
||||||
- Fetch & extract some archives, as shown in this table:
|
- Fetch & extract some archives, as shown in this table:
|
||||||
|
|
||||||
| Archive file | Top-level dir inside | Target directory |
|
| Archive file | Top-level dir inside | Target directory |
|
||||||
| ----------------------------------- | ----------------------- | ----------------------------------- |
|
| ----------------------------------- | ----------------------- | ----------------------------------- |
|
||||||
| `android-ndk-r25b-linux.zip` | `android-ndk-r25b` | `android/android-ndk-r25b` |
|
| `android-ndk-r25c-linux.zip` | `android-ndk-r25c` | `android/android-ndk-r25c` |
|
||||||
| `build-tools_r33-linux.zip` | `android-13` | `android/build-tools/33.0.0` |
|
| `build-tools_r33-linux.zip` | `android-13` | `android/build-tools/33.0.0` |
|
||||||
| `commandlinetools-linux-8512546_latest.zip` | `cmdline-tools` | `android/cmdline-tools/latest` |
|
| `commandlinetools-linux-8512546_latest.zip` | `cmdline-tools` | `android/cmdline-tools/latest` |
|
||||||
| `platform-30_r03.zip` | `android-11` | `android/platforms/android-30` |
|
| `platform-30_r03.zip` | `android-11` | `android/platforms/android-30` |
|
||||||
@ -106,7 +102,7 @@ So after that you will get:
|
|||||||
|
|
||||||
```
|
```
|
||||||
android
|
android
|
||||||
├── android-ndk-r25b
|
├── android-ndk-r25c
|
||||||
├── build-tools
|
├── build-tools
|
||||||
│ └── 33.0.0
|
│ └── 33.0.0
|
||||||
├── cmdline-tools
|
├── cmdline-tools
|
||||||
@ -125,7 +121,7 @@ System doesn’t understand it. Let’s replace them as symlinks:
|
|||||||
```bash
|
```bash
|
||||||
# you may already have these from p4a guide
|
# you may already have these from p4a guide
|
||||||
ANDROIDSDK="$DIR_BUILD/android"
|
ANDROIDSDK="$DIR_BUILD/android"
|
||||||
ANDROIDNDK="$DIR_BUILD/android/android-ndk-r25b"
|
ANDROIDNDK="$DIR_BUILD/android/android-ndk-r25c"
|
||||||
# feel free to check this script
|
# feel free to check this script
|
||||||
python3 $DIR_GIT/Cat-Printer/build-android/fix-ndk-execs.py $ANDROIDNDK
|
python3 $DIR_GIT/Cat-Printer/build-android/fix-ndk-execs.py $ANDROIDNDK
|
||||||
```
|
```
|
||||||
@ -147,10 +143,10 @@ after that, restart docker service, or reboot.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# let’s create the container by first pulling the image
|
# let’s create the container by first pulling the image
|
||||||
docker pull ubuntu:latest
|
docker pull archlinux:latest
|
||||||
# please, pass previously mentioned directories (or their parent) via -v parameter, we will access them here
|
# please, pass previously mentioned directories (or their parent) via -v parameter, we will access them here
|
||||||
# example: `-v /source1/android:/target1/android -v /source2/git-repo:/target2/git-repo`
|
# example: `-v /source1/android:/target1/android -v /source2/git-repo:/target2/git-repo`
|
||||||
docker create --name catbuild -v /mnt/data:/mnt/data --tty -i ubuntu
|
docker create --name catbuild -v /mnt/data:/mnt/data --tty -i archlinux
|
||||||
|
|
||||||
# From now on, start the container like this
|
# From now on, start the container like this
|
||||||
docker start -i catbuild
|
docker start -i catbuild
|
||||||
@ -161,17 +157,13 @@ docker start -i catbuild
|
|||||||
OK, we are now inside the container shell. Set it up:
|
OK, we are now inside the container shell. Set it up:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# (Optional) use a Ubuntu repository mirror
|
# (Optional) use a repository mirror:
|
||||||
# sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
|
# cd /etc/pacman.d; mv mirrorlist mirrorlist.bak; echo 'Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' >mirrorlist
|
||||||
dpkg --add-architecture i386
|
pacman -Syuu jdk-openjdk python3 python-pip git cython zip nano vim tar wget unzip base-devel clang lld libffi
|
||||||
apt update
|
|
||||||
apt upgrade
|
|
||||||
# find python-for-android dependencies here:
|
# find python-for-android dependencies here:
|
||||||
# https://python-for-android.readthedocs.io/en/latest/quickstart/#installing-dependencies
|
# https://python-for-android.readthedocs.io/en/latest/quickstart/#installing-dependencies
|
||||||
# there should be a command for Ubuntu that you can directly run
|
# there should be command for Arch/Ubuntu that you can directly run
|
||||||
# ... though we need more
|
# (Optional) use a pypi mirror:
|
||||||
apt install -y python3-pip lld libffi-dev zip nano
|
|
||||||
# (Optional) use a pypi mirror
|
|
||||||
# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
pip install python-for-android cython bleak
|
pip install python-for-android cython bleak
|
||||||
```
|
```
|
||||||
@ -187,7 +179,7 @@ We should glue them up by hand.
|
|||||||
echo '
|
echo '
|
||||||
export DIR_BUILD="/mnt/data/@"
|
export DIR_BUILD="/mnt/data/@"
|
||||||
export ANDROIDSDK="$DIR_BUILD/android"
|
export ANDROIDSDK="$DIR_BUILD/android"
|
||||||
export ANDROIDNDK="$DIR_BUILD/android/android-ndk-r25b"
|
export ANDROIDNDK="$DIR_BUILD/android/android-ndk-r25c"
|
||||||
export ANDROIDAPI="30"
|
export ANDROIDAPI="30"
|
||||||
export NDKAPI="21"' >> .bashrc
|
export NDKAPI="21"' >> .bashrc
|
||||||
|
|
||||||
@ -200,6 +192,7 @@ source ~/.bashrc
|
|||||||
```bash
|
```bash
|
||||||
# define shortcut(s). use your target paths!
|
# define shortcut(s). use your target paths!
|
||||||
DIR_GIT="$DIR_BUILD/git-repo/"
|
DIR_GIT="$DIR_BUILD/git-repo/"
|
||||||
|
# note this involves python version, change as needed
|
||||||
DIR_P4A="/usr/local/lib/python3.10/dist-packages/pythonforandroid/"
|
DIR_P4A="/usr/local/lib/python3.10/dist-packages/pythonforandroid/"
|
||||||
|
|
||||||
# p4a will generate some intermediate data. “expose” this to the host for convenient manipulation.
|
# p4a will generate some intermediate data. “expose” this to the host for convenient manipulation.
|
||||||
@ -343,7 +336,7 @@ Try the ultimate helper `1-build.sh`, if you also have everything in [developmen
|
|||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
Common issues and fixes:
|
### Common
|
||||||
|
|
||||||
| Error message | Fix |
|
| Error message | Fix |
|
||||||
|-|-|
|
|-|-|
|
||||||
@ -354,6 +347,33 @@ Common issues and fixes:
|
|||||||
| No such file or directory `build-android/dist` | Create a bare bundle before creating an APK |
|
| No such file or directory `build-android/dist` | Create a bare bundle before creating an APK |
|
||||||
| JAVA_HOME is not set and no 'java' command could be found in your PATH. | Install a JDK (e.g. `openjdk-19-jdk`) |
|
| JAVA_HOME is not set and no 'java' command could be found in your PATH. | Install a JDK (e.g. `openjdk-19-jdk`) |
|
||||||
|
|
||||||
|
### Special
|
||||||
|
|
||||||
|
Something like these:
|
||||||
|
(pardon me for not memorizing the log well)
|
||||||
|
|
||||||
|
```
|
||||||
|
… platform is . …
|
||||||
|
is unsupported, assuming android-19 …
|
||||||
|
……
|
||||||
|
……
|
||||||
|
……
|
||||||
|
crtbegin… … not found
|
||||||
|
…
|
||||||
|
crtend… … not found
|
||||||
|
```
|
||||||
|
|
||||||
|
Change `$ANDROIDNDK/build/gmsl/__gmsl` line 512:
|
||||||
|
```
|
||||||
|
int_encode = $(__gmsl_tr1)$(wordlist 1,$1,$(__gmsl_input_int))
|
||||||
|
```
|
||||||
|
to this:
|
||||||
|
```
|
||||||
|
int_encode = $(__gmsl_tr1)$(wordlist 1,$(if $1, $1,0),$(__gmsl_input_int))
|
||||||
|
```
|
||||||
|
|
||||||
|
(Thanks to a comment around [here](https://stackoverflow.com/questions/10285242/openssl-using-androids-ndk-problems#answer-14369078))
|
||||||
|
|
||||||
## The End
|
## The End
|
||||||
|
|
||||||
You made it! You now have ability to contribute much more, outside of Cat-Printer. Try to bring an app in your mind to reality, with just Python, Web, and this build environment.
|
You made it! You now have ability to contribute much more, outside of Cat-Printer. Try to bring an app in your mind to reality, with just Python, Web, and this build environment.
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
export version=`cat ../version`
|
export version=`cat ../version`
|
||||||
for i in $(find | grep -E '.*\.pyc'); do rm $i; done
|
for i in $(find | grep -E '.*\.pyc'); do rm $i; done
|
||||||
for i in $(find | grep -E '__pycache__'); do rm -d $i; done
|
for i in $(find | grep -E '__pycache__'); do rm -d $i; done
|
||||||
python3 bundle.py $version
|
# python3 bundle.py $version
|
||||||
python3 bundle.py -w $version
|
# python3 bundle.py -w $version
|
||||||
python3 bundle.py -b $version
|
python3 bundle.py -b $version
|
||||||
|
Loading…
x
Reference in New Issue
Block a user