diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index dcb6d2ac3b..156de5eae2 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -4,7 +4,7 @@ import hashlib import json from os.path import ( - dirname, join, isfile, realpath, + dirname, join, isfile, isdir, realpath, relpath, split, exists, basename ) from os import environ, listdir, makedirs, remove @@ -342,10 +342,67 @@ def make_package(args): res_dir = "src/main/res" default_icon = 'templates/kivy-icon.png' default_presplash = 'templates/kivy-presplash.jpg' + + # Clean res directory + shutil.rmtree(res_dir) + + # Create default p4a res dirs + default_res_dirs = [ + "drawable", "drawable-mdpi", "drawable-hdpi", "drawable-xhdpi", + "drawable-xxhdpi", "layout", "mipmap", "mipmap-anydpi-v26", "values", + "xml" + ] + for dir in default_res_dirs: + ensure_dir(join(res_dir, dir)) + + # Copy default xml layout files + if get_bootstrap_name() == "sdl2": + default_layout_xmls = [ + "chooser_item.xml", "main.xml", "project_chooser.xml", + "project_empty.xml" + ] + for xml in default_layout_xmls: + shutil.copy( + join("templates", xml), + join(res_dir, "layout", xml) + ) + + if args.res: + target_res_dirs = [ + filename for filename in listdir(res_dir) + if isdir(join(res_dir, filename)) + ] + source_res_dirs = [ + filename for filename in listdir(args.res) + if isdir(join(args.res, filename)) + ] + for directory in source_res_dirs: + if directory not in target_res_dirs: + ensure_dir(join(res_dir, directory)) + source_dir = join(args.res, directory) + target_dir = join(res_dir, directory) + + source_dir_files = [ + filename for filename in listdir(source_dir) + if isfile(join(source_dir, filename)) + ] + for filename in source_dir_files: + shutil.copy( + join(source_dir, filename), + join(target_dir, filename) + ) + + # Removes :Zone.Identifier files, for WSL users. + # Issue: https://github.com/microsoft/WSL/issues/7456 + for file in listdir(join(res_dir, directory)): + if file.endswith(':Zone.Identifier'): + remove(join(res_dir, directory, file)) + shutil.copy( args.icon or default_icon, join(res_dir, 'mipmap/icon.png') ) + if args.icon_fg and args.icon_bg: shutil.copy(args.icon_fg, join(res_dir, 'mipmap/icon_foreground.png')) shutil.copy(args.icon_bg, join(res_dir, 'mipmap/icon_background.png')) @@ -690,6 +747,8 @@ 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('--add-res', dest='res', + help=('Copy/overwrite directories and its files in the android res directory')) ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' 'the application.')) diff --git a/pythonforandroid/bootstraps/common/build/templates/chooser_item.xml b/pythonforandroid/bootstraps/common/build/templates/chooser_item.xml new file mode 100644 index 0000000000..1823b13223 --- /dev/null +++ b/pythonforandroid/bootstraps/common/build/templates/chooser_item.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + diff --git a/pythonforandroid/bootstraps/common/build/templates/main.xml b/pythonforandroid/bootstraps/common/build/templates/main.xml new file mode 100644 index 0000000000..123c4b6eac --- /dev/null +++ b/pythonforandroid/bootstraps/common/build/templates/main.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/pythonforandroid/bootstraps/common/build/templates/project_chooser.xml b/pythonforandroid/bootstraps/common/build/templates/project_chooser.xml new file mode 100644 index 0000000000..23828e644b --- /dev/null +++ b/pythonforandroid/bootstraps/common/build/templates/project_chooser.xml @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/pythonforandroid/bootstraps/common/build/templates/project_empty.xml b/pythonforandroid/bootstraps/common/build/templates/project_empty.xml new file mode 100644 index 0000000000..ee5481421d --- /dev/null +++ b/pythonforandroid/bootstraps/common/build/templates/project_empty.xml @@ -0,0 +1,15 @@ + + + + + + +