Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/buildoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,24 @@ 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(":")
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), dirs_exist_ok=True)

default_icon = 'templates/kivy-icon.png'
default_presplash = 'templates/kivy-presplash.jpg'
shutil.copy(
Expand Down Expand Up @@ -698,6 +716,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.'))
Expand Down
12 changes: 12 additions & 0 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down Expand Up @@ -1000,6 +1004,14 @@ 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
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):
argx = arg.split('=')
if argx[0] in fix_args:
Expand Down