From 3d5425cce02a65d5f792eea5b8ad1ad9221e9f8f Mon Sep 17 00:00:00 2001 From: RobertF <34464649+RobertFlatt@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:24:03 -1000 Subject: [PATCH 1/7] add_resources --- pythonforandroid/toolchain.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 1b81aa923c..feadb89e59 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -512,6 +512,10 @@ def add_parser(subparsers, *args, **kwargs): '--add-asset', dest='assets', action="append", default=[], help='Put this in the assets folder in the apk.') + parser_packaging.add_argument( + '--add-resource', dest='resources', + action="append", default=[], + help='Put this in the res folder in the apk.') parser_packaging.add_argument( '--private', dest='private', help='the directory with the app source code files' + @@ -1000,6 +1004,13 @@ def _fix_args(args): asset_src = asset_dest = asset # take abspath now, because build.py will be run in bootstrap dir unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest] + for resource in args.resources: + if ":" in resource: + resource_src, resource_dest = resource.split(":") + else: + resource_src = resource_dest = resource + # take abspath now, because build.py will be run in bootstrap dir + unknown_args += ["--resource", os.path.abspath(resource_src)+":"+resource_dest] for i, arg in enumerate(unknown_args): argx = arg.split('=') if argx[0] in fix_args: From 9cb1ab693ef033317194af29ef3a3b64eccdb1d4 Mon Sep 17 00:00:00 2001 From: RobertF <34464649+RobertFlatt@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:45:20 -1000 Subject: [PATCH 2/7] add_resource --- pythonforandroid/bootstraps/common/build/build.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 6885a333df..6b38ca4b3b 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -340,6 +340,17 @@ def make_package(args): # Prepare some variables for templating process res_dir = "src/main/res" + # Add user resouces + shutil.rmtree(res_dir, ignore_errors=True) + ensure_dir(res_dir) + for resource in args.resources: + resource_src, resource_dest = resource.split(":") + if isfile(realpath(resource_src)): + ensure_dir(dirname(join(res_dir, resource_dest))) + shutil.copy(realpath(resource_src), join(res_dir, resource_dest)) + else: + shutil.copytree(realpath(resource_src), join(res_dir, resource_dest)) + default_icon = 'templates/kivy-icon.png' default_presplash = 'templates/kivy-presplash.jpg' shutil.copy( @@ -698,6 +709,10 @@ def parse_args_and_make_package(args=None): action="append", default=[], metavar="/path/to/source:dest", help='Put this in the assets folder at assets/dest') + ap.add_argument('--resource', dest='resources', + action="append", default=[], + metavar="/path/to/source:kind/asset", + help='Put this in the res folder at res/kind') ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' 'the application.')) From ed8b865511495ca3e74e4cfa2c5693f8b12d48bd Mon Sep 17 00:00:00 2001 From: RobertF <34464649+RobertFlatt@users.noreply.github.com> Date: Sat, 8 Oct 2022 16:31:57 -1000 Subject: [PATCH 3/7] Update build.py --- pythonforandroid/bootstraps/common/build/build.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 6b38ca4b3b..7d1984b642 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -341,8 +341,6 @@ def make_package(args): # Prepare some variables for templating process res_dir = "src/main/res" # Add user resouces - shutil.rmtree(res_dir, ignore_errors=True) - ensure_dir(res_dir) for resource in args.resources: resource_src, resource_dest = resource.split(":") if isfile(realpath(resource_src)): From 20ccb7c04975e7e7393f7cb51100c29d16c38924 Mon Sep 17 00:00:00 2001 From: RobertFlatt <34464649+RobertFlatt@users.noreply.github.com> Date: Wed, 12 Oct 2022 17:10:33 -1000 Subject: [PATCH 4/7] stateless --- pythonforandroid/bootstraps/common/build/build.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 7d1984b642..c9a992fc00 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -340,6 +340,14 @@ def make_package(args): # Prepare some variables for templating process res_dir = "src/main/res" + res_dir_initial = "src/res_initial" + # make res_dir stateless + if exists(res_dir_initial): + shutil.rmtree(res_dir, ignore_errors=True) + shutil.copytree(res_dir_initial, res_dir) + else: + shutil.copytree(res_dir, res_dir_initial) + # Add user resouces for resource in args.resources: resource_src, resource_dest = resource.split(":") @@ -347,7 +355,8 @@ def make_package(args): ensure_dir(dirname(join(res_dir, resource_dest))) shutil.copy(realpath(resource_src), join(res_dir, resource_dest)) else: - shutil.copytree(realpath(resource_src), join(res_dir, resource_dest)) + shutil.copytree(realpath(resource_src), + join(res_dir, resource_dest), dirs_exist_ok=True) default_icon = 'templates/kivy-icon.png' default_presplash = 'templates/kivy-presplash.jpg' From 9a32a9c0012c6540d4480140a038ec1f8d0edb29 Mon Sep 17 00:00:00 2001 From: RobertFlatt <34464649+RobertFlatt@users.noreply.github.com> Date: Wed, 12 Oct 2022 17:11:39 -1000 Subject: [PATCH 5/7] multiple kinds --- pythonforandroid/toolchain.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index feadb89e59..daf895e897 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -1008,7 +1008,8 @@ def _fix_args(args): if ":" in resource: resource_src, resource_dest = resource.split(":") else: - resource_src = resource_dest = resource + resource_src = resource + resource_dest = "" # take abspath now, because build.py will be run in bootstrap dir unknown_args += ["--resource", os.path.abspath(resource_src)+":"+resource_dest] for i, arg in enumerate(unknown_args): From 76e52043274ee1b146e838b2e36e0f7ed4d61493 Mon Sep 17 00:00:00 2001 From: RobertFlatt <34464649+RobertFlatt@users.noreply.github.com> Date: Wed, 12 Oct 2022 17:16:01 -1000 Subject: [PATCH 6/7] pep8 --- pythonforandroid/bootstraps/common/build/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index c9a992fc00..a9f4dde42e 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -347,7 +347,7 @@ def make_package(args): shutil.copytree(res_dir_initial, res_dir) else: shutil.copytree(res_dir, res_dir_initial) - + # Add user resouces for resource in args.resources: resource_src, resource_dest = resource.split(":") From fa2cb13f8fbb2b57faee225248844cdf34a1ef58 Mon Sep 17 00:00:00 2001 From: RobertF <34464649+RobertFlatt@users.noreply.github.com> Date: Sun, 16 Oct 2022 14:58:38 -1000 Subject: [PATCH 7/7] --add_resource --- doc/source/buildoptions.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/buildoptions.rst b/doc/source/buildoptions.rst index d9f97175a2..cfe8bc1a04 100644 --- a/doc/source/buildoptions.rst +++ b/doc/source/buildoptions.rst @@ -91,6 +91,7 @@ options (this list may not be exhaustive): - ``--add-source``: Add a source directory to the app's Java code. - ``--no-compile-pyo``: Do not optimise .py files to .pyo. - ``--enable-androidx``: Enable AndroidX support library. +- ``--add-resource``: Put this file or directory in the apk res directory. webview