Skip to content

Commit

Permalink
test apk build
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMelody committed Dec 30, 2024
1 parent 731db96 commit 633a342
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 129 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,58 @@ jobs:
tag_name: v${{ needs.make-outputs.outputs.VERSION }}
files: |
./packaging/dist/LibreSVIP-${{ needs.make-outputs.outputs.VERSION }}.macos-arm64.dmg
release_apk:
runs-on: ubuntu-latest
needs: [make-outputs]
env:
FLUTTER_VERSION: "3.24.4"

steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"

- name: Install Python Dependencies
run: |
uv venv --python 3.12
uv sync --extra mobile
uv run python -m ensurepip --upgrade
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}

- name: Setup Java JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'

- name: Flet Build APK
run: |
flutter config --no-analytics
cd packaging
uv run python install_mobile_requirements.py --platform android_24_arm64_v8a --arch arm64-v8a
uv run python install_mobile_requirements.py --platform android_24_armeabi_v7a --arch armeabi-v7a
uv run python install_mobile_requirements.py --platform android_24_x86_64 --arch x86_64
bash build_apk.sh
mv build/apk/app-release.apk build/apk/LibreSVIP-${{ needs.make-outputs.outputs.VERSION }}.apk
cd ..
- name: Upload APK Artifact
uses: actions/upload-artifact@v4
with:
name: libresvip-android.zip
path: build/apk

- name: Create Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
tag_name: v${{ needs.make-outputs.outputs.VERSION }}
files: |
./packaging/build/apk/LibreSVIP-${{ needs.make-outputs.outputs.VERSION }}.apk
129 changes: 0 additions & 129 deletions packaging/download_android_wheels.py

This file was deleted.

128 changes: 128 additions & 0 deletions packaging/install_mobile_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import argparse
import pathlib
import subprocess
import sys

from loguru import logger
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement


def install_mobile_requirements(platform: str, arch: str) -> None:
cwd = pathlib.Path()

python_version = "3.12"
wheels_dir = cwd / f"build/site-packages/{arch}"
if not wheels_dir.exists():
wheels_dir.mkdir(parents=True, exist_ok=True)
common_args = [
sys.executable,
"-m",
"pip",
"install",
"--no-deps",
"--target",
str(wheels_dir),
"--upgrade",
"--no-compile",
]

native_packages = {
"cffi": None,
"lxml": None,
"markupsafe": None,
"protobuf": None,
"pycryptodomex": None,
"pydantic-core": "==2.23.3",
"pyyaml": None,
"regex": None,
"ruamel-yaml-clib": None,
"zstandard": None,
}

requirements_path = cwd / "requirements-android.txt"
requirements = requirements_path.read_text().splitlines()
project_wheel = next((cwd / "../dist/").glob("*.whl"))
requirements.insert(0, f"libresvip @ {project_wheel.resolve()!s}")
for requirement_str in requirements:
try:
requirement = Requirement(requirement_str)
except InvalidRequirement:
continue
if (
requirement.marker is None
or requirement.marker.evaluate(
environment={
"platform_system": "Android",
"python_version": python_version,
"python_full_version": python_version,
"sys_platform": "android",
}
)
is True
):
logger.info(f"Installing {requirement.name}...")
if requirement.name in native_packages:
subprocess.check_call(
[
*common_args,
f"{requirement.name}{native_packages[requirement.name] or ''}",
"--platform",
platform,
"--only-binary",
":all:",
"--python-version",
python_version,
"--index-url",
"https://pypi.flet.dev/",
]
)
elif requirement.name == "pymediainfo":
subprocess.check_call(
[
*common_args,
f"{requirement.name}{requirement.specifier}",
"--no-binary",
":all:",
]
)
else:
if requirement.name == "pydantic":
requirement_str = "pydantic==2.9.1"
elif requirement.url:
requirement_str = requirement.url
else:
requirement_str = f"{requirement.name}{requirement.specifier}"
try:
subprocess.check_call(
[
*common_args,
requirement_str,
"--platform",
"none",
"--only-binary",
":all:",
]
)
except subprocess.CalledProcessError:
subprocess.check_call(
[
*common_args,
requirement_str,
"--no-binary",
":all:",
]
)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--platform",
default="android_24_arm64_v8a",
)
parser.add_argument(
"--arch",
default="arm64-v8a",
)
args = parser.parse_args()
install_mobile_requirements(args.platform, args.arch)

0 comments on commit 633a342

Please sign in to comment.