ArtemSBulgakov / buildozer-action

GitHub Action to build your Python application with Buildozer
MIT License
73 stars 71 forks source link

How to modify "AndroidManifest.tmpl.xml" before "buildozer-action@v1" ? #20

Closed manatlan closed 2 years ago

manatlan commented 2 years ago

HI,

I need to modify "AndroidManifest.tmpl.xml", before the build process (to add a android:usesCleartextTraffic="true" in )

How can I do that, with the github/action ?

thanks in advance

ArtemSBulgakov commented 2 years ago

Hi! You can use python-for-android hooks for this.

Add line to buildozer.spec:

# (str) Filename to the hook for p4a
p4a.hook = p4a/hook.py

Add file p4a/hook.py with your code (you need hook after_apk_build, it is called from here).

I use this to change android.screenOrientation, you can change for your case:

import os
import shutil
from pathlib import Path
from pythonforandroid.toolchain import ToolchainCL

def after_apk_build(toolchain: ToolchainCL):
    manifest_file = Path(toolchain._dist.dist_dir) / "src" / "main" / "AndroidManifest.xml"
    old_manifest = manifest_file.read_text(encoding="utf-8")
    new_manifest = old_manifest.replace(
        'android:screenOrientation="portrait"',
        'android:screenOrientation="userPortrait"',
    )
    manifest_file.write_text(new_manifest, encoding="utf-8")
    if old_manifest != new_manifest:
        print("Set orientation SUCCESSFULLY")
    else:
        print("Set orientation FAILED")
manatlan commented 2 years ago

Thanks, you are a god ! You save me ... it now works (it builds an apk !) : https://github.com/manatlan/htagapk

But how can you explain ?!

The resulted apk/package can't be installed on my phone (xiaomi mi9)....

While, locally (on my ubu lts, the same repo/srcs), a simple buildozer android debug deploy run install it and run it, without trouble ?!

Have you got an idea ?

But thanks for the p4a tips !!!!

ArtemSBulgakov commented 2 years ago

Apk from this build installs correctly on my Samsung S21.

What error do you get?

manatlan commented 2 years ago

Update !

It works like a charm ! forget my latest comment ! (In fact, "Google Files" refused to install the github/apk .... but using another process : it installs, and it works !)

Big thanks to you !!

ArtemSBulgakov commented 2 years ago

Glad to hear it, good luck with your projects!