Closed manatlan closed 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")
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 !!!!
Apk from this build installs correctly on my Samsung S21.
What error do you get?
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 !!
Glad to hear it, good luck with your projects!
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