Skip to content

Instantly share code, notes, and snippets.

@sync1211
Last active February 17, 2023 08:45
Show Gist options
  • Save sync1211/ee92c90f74c27aace0f0ac9113b8a891 to your computer and use it in GitHub Desktop.
Save sync1211/ee92c90f74c27aace0f0ac9113b8a891 to your computer and use it in GitHub Desktop.

Prepare docker environment

Set up docker env

sudo docker pull archlinux:latest
sudo docker create --name catprinter -v $(pwd):/mnt/catprinter --tty -i archlinux
sudo docker start catprinter
sudo docker attach catprinter

Set up build environment

Install dependencies

pacman -Syuu jdk-openjdk python3 python-pip git cython zip nano vim tar wget unzip base-devel clang lld
pip install python-for-android bleak

Set environment variables

echo '
DIR_BUILD="/mnt/catprinter"
ANDROIDSDK="$DIR_BUILD/android-sdk"
ANDROIDNDK="$DIR_BUILD/android-ndk-r25c"
ANDROIDNDKVER="r25c"
ANDROIDAPI="30"
NDKAPI="21"' >> ~/.bashrc

source ~/.bashrc

Download SDK and NDK

# NDK
wget https://dl.google.com/android/repository/android-ndk-r25c-linux.zip
unzip android-ndk-r25c-linux.zip
rm android-ndk-r25c-linux.zip

python3 $DIR_GIT/Cat-Printer/build-android/fix-ndk-execs.py $ANDROIDNDK

# SDK
wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip
unzip commandlinetools-linux-9477386_latest.zip
rm commandlinetools-linux-9477386_latest.zip
mkdir -p android-sdk/cmdline-tools/
mv cmdline-tools android-sdk/cmdline-tools/latest

# Build tools
export JAVA_HOME=/usr/lib/jvm/default
android-sdk/cmdline-tools/latest/bin/sdkmanager "platforms;android-30"
android-sdk/cmdline-tools/latest/bin/sdkmanager "build-tools;33.0.2"

Set up build

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

git clone https://github.com/delight-im/Android-AdvancedWebView.git
ln -s ../../Android-AdvancedWebView/Source/library/src/main/java Cat-Printer/build-android/advancedwebview

Modify files

DIR_P4A="/usr/lib/python3.10/site-packages/pythonforandroid"
DIR_GIT=$(pwd)

# Add bleak receipe to p4a
ln -s $DIR_GIT/bleak/bleak/backends/p4android/recipes/bleak $DIR_P4A/recipes/bleak

# Install patched PythonActivity
wget https://gist.githubusercontent.com/sync1211/1f8a7a05700129037a4f3bb2497900b2/raw/eb69bb152922e9913de6080d75b6a11207e6f228/PythonActivity.java -O PythonActivity.java
mv PythonActivity.java $DIR_P4A/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java

# Install patched AdvancedWebView
wget https://gist.githubusercontent.com/sync1211/2d3261bb2ae5e687146782b71dfbe512/raw/c4fd9c61abe4c3e7e78791d6f47110c764dc50f5/AdvancedWebView.java
mv AdvancedWebView.java Android-AdvancedWebView/Source/library/src/main/java/im/delight/android/webview/AdvancedWebView.java

# Add icon
cp $DIR_GIT/Cat-Printer/www/_load.html $DIR_GIT/Cat-Printer/www/icon.svg $DIR_P4A/bootstraps/webview/build/webview_includes/

Build

cd Cat-Printer/build-android/
./0-build-android.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment