Last active
April 28, 2024 03:37
-
-
Save tito/2cb071659406086dc7c81f3cfe218aca to your computer and use it in GitHub Desktop.
Python for android / buildozer / androidx (MAY NOT WORK)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to add in the spcec: | |
android.api = 28 | |
android.minapi = 26 | |
android.ndk = 17c | |
p4a.hook = p4a_hook.py | |
# i have my own set of java tools, don't use it if you don't want it | |
android.add_src = java/src/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from glob import glob | |
from os.path import dirname, join, basename | |
curdir = dirname(__file__) | |
sys.path += [curdir] | |
files = glob(join(curdir, "hook_*.py")) | |
def after_apk_build(toolchain): | |
print("HOOK AFTER APK BUILD", toolchain) | |
dist_dir = toolchain._dist.dist_dir | |
print("dist_dir", dist_dir) | |
data = """ | |
android.useAndroidX=true | |
android.enableJetifier=true | |
""" | |
with open(join(dist_dir, "gradle.properties"), "w") as fd: | |
fd.write(data) | |
print("Use androidX") | |
print(data) | |
deps = """ | |
dependencies { | |
implementation 'androidx.work:work-runtime:2.2.0' | |
implementation 'androidx.annotation:annotation:1.1.0' | |
""" | |
data = open(join(dist_dir, "build.gradle")).read() | |
if "androidx.appcompat:appcompat" not in data: | |
data = data.replace("\ndependencies {", deps) | |
with open(join(dist_dir, "build.gradle"), "w") as fd: | |
fd.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment