77import sh
88import shlex
99import shutil
10+ from pathlib import Path
1011
1112from pythonforandroid .logger import (shprint , info , info_main , logger , debug )
1213from pythonforandroid .util import (
@@ -40,6 +41,36 @@ def copy_files(src_root, dest_root, override=True, symlink=False):
4041 os .makedirs (dest_file )
4142
4243
44+ def copytree_filtered (src , dst , skip_dirs = None ):
45+ """
46+ Copy directory tree while skipping explicitly specified directories in src.
47+ """
48+
49+ info (f"Copying { src } to { dst } with skip dirs: { skip_dirs } " )
50+
51+ src = Path (src )
52+ dst = Path (dst )
53+ skip_dirs = set (Path (p ) for p in (skip_dirs or []))
54+
55+ def should_skip (rel_path ):
56+ # match exact directory path only
57+ return any (rel_path == skip or skip in rel_path .parents for skip in skip_dirs )
58+
59+ for item in src .rglob ("*" ):
60+ rel = item .relative_to (src )
61+
62+ if should_skip (rel ):
63+ continue
64+
65+ target = dst / rel
66+
67+ if item .is_dir ():
68+ target .mkdir (parents = True , exist_ok = True )
69+ else :
70+ target .parent .mkdir (parents = True , exist_ok = True )
71+ shutil .copy2 (item , target )
72+
73+
4374default_recipe_priorities = [
4475 "webview" , "sdl2" , "sdl3" , "service_only" # last is highest
4576]
@@ -91,6 +122,10 @@ class Bootstrap:
91122 from Bootstrap.get_bootstrap_from_recipes.
92123 '''
93124
125+ # Directories to exclude during copy (relative to src root).
126+ # Used to reduce final build size and exclude unnecessary sources for final build.
127+ skip_dirs = []
128+
94129 # Other things a Bootstrap might need to track (maybe separately):
95130 # ndk_main.c
96131 # whitelist.txt
@@ -201,6 +236,7 @@ def _assemble_distribution_for_arch(self, arch):
201236 self .strip_libraries (arch )
202237 self .fry_eggs (site_packages_dir )
203238
239+
204240 def assemble_distribution (self ):
205241 """Assemble the distribution by copying files and creating Python bundle.
206242
@@ -211,7 +247,7 @@ def assemble_distribution(self):
211247 info_main (f'# Creating Android project ({ self .name } )' )
212248
213249 rmdir (self .dist_dir )
214- shprint ( sh . cp , '-r' , self .build_dir , self .dist_dir )
250+ copytree_filtered ( self . build_dir , self .dist_dir , skip_dirs = self .skip_dirs )
215251
216252 with current_directory (self .dist_dir ):
217253 with open ('local.properties' , 'w' ) as fileh :
0 commit comments