Skip to content

Commit 550f2d1

Browse files
author
Jonas Thiem
committed
Fix debug build missing symbols and other related issues
- fixes that a debug (non-`--release`) `.apk` build won't actually enable gdb debugging in the manifest - renames `build.py`'s `parse_args` to `parse_args_and_make_package` because that is what it appears to be actually doing 😄 - makes SDL2 and any standard `NDKRecipe` build with `NDK_DEBUG=1` when `--release` is not specified to add debugging symbols
1 parent 85207a0 commit 550f2d1

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ def make_package(args):
488488
"args": args,
489489
"service": service,
490490
"service_names": service_names,
491-
"android_api": android_api
491+
"android_api": android_api,
492+
"debug": "debug" in args.build_mode,
492493
}
493494
if get_bootstrap_name() == "sdl2":
494495
render_args["url_scheme"] = url_scheme
@@ -576,7 +577,7 @@ def make_package(args):
576577
raise e
577578

578579

579-
def parse_args(args=None):
580+
def parse_args_and_make_package(args=None):
580581
global BLACKLIST_PATTERNS, WHITELIST_PATTERNS, PYTHON
581582

582583
# Get the default minsdk, equal to the NDK API that this dist is built against
@@ -676,6 +677,10 @@ def parse_args(args=None):
676677
default=join(curdir, 'whitelist.txt'),
677678
help=('Use a whitelist file to prevent blacklisting of '
678679
'file in the final APK'))
680+
ap.add_argument('--release', dest='build_mode', action='store_const',
681+
const='release', default='debug',
682+
help='Build your app as a non-debug release build. '
683+
'(Disables gdb debugging among other things)')
679684
ap.add_argument('--add-jar', dest='add_jar', action='append',
680685
help=('Add a Java .jar to the libs, so you can access its '
681686
'classes with pyjnius. You can specify this '
@@ -820,4 +825,4 @@ def _read_configuration():
820825

821826

822827
if __name__ == "__main__":
823-
parse_args()
828+
parse_args_and_make_package()

pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
An example Java class can be found in README-android.txt
5353
-->
5454
<application android:label="@string/app_name"
55+
{% if debug %}android:debuggable="true"{% endif %}
5556
android:icon="@drawable/icon"
5657
android:allowBackup="{{ args.allow_backup }}"
5758
android:theme="@android:style/Theme.NoTitleBar{% if not args.window %}.Fullscreen{% endif %}"

pythonforandroid/build.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def not_has_package(self, name, arch=None):
517517

518518

519519
def build_recipes(build_order, python_modules, ctx, project_dir,
520-
ignore_project_setup_py=False
520+
ignore_project_setup_py=False, debug_build=False,
521521
):
522522
# Put recipes in correct build order
523523
info_notify("Recipe build order is {}".format(build_order))
@@ -527,7 +527,10 @@ def build_recipes(build_order, python_modules, ctx, project_dir,
527527
('The requirements ({}) were not found as recipes, they will be '
528528
'installed with pip.').format(', '.join(python_modules)))
529529

530-
recipes = [Recipe.get_recipe(name, ctx) for name in build_order]
530+
recipes = [
531+
Recipe.get_recipe(name, ctx, build_as_debuggable=debug_build)
532+
for name in build_order
533+
]
531534

532535
# download is arch independent
533536
info_main('# Downloading recipes ')

pythonforandroid/recipe.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class Recipe(with_metaclass(RecipeMeta)):
106106

107107
archs = ['armeabi'] # Not currently implemented properly
108108

109+
build_as_debuggable = False
110+
''' Whether to build with debugging symbols, e.g. NDK_DEBUG=1 for
111+
NDK-based recipes '''
112+
109113
@property
110114
def version(self):
111115
key = 'VERSION_' + self.name
@@ -577,12 +581,13 @@ def list_recipes(cls, ctx):
577581
yield name
578582

579583
@classmethod
580-
def get_recipe(cls, name, ctx):
584+
def get_recipe(cls, name, ctx, build_as_debuggable=False):
581585
'''Returns the Recipe with the given name, if it exists.'''
582586
name = name.lower()
583587
if not hasattr(cls, "recipes"):
584588
cls.recipes = {}
585589
if name in cls.recipes:
590+
cls.recipes[name].build_as_debuggable = build_as_debuggable
586591
return cls.recipes[name]
587592

588593
recipe_file = None
@@ -607,6 +612,7 @@ def get_recipe(cls, name, ctx):
607612
if len(logger.handlers) > 1:
608613
logger.removeHandler(logger.handlers[1])
609614
recipe = mod.recipe
615+
recipe.build_as_debuggable = build_as_debuggable
610616
recipe.ctx = ctx
611617
cls.recipes[name.lower()] = recipe
612618
return recipe
@@ -695,6 +701,7 @@ def build_arch(self, arch, *extra_args):
695701
shprint(
696702
sh.ndk_build,
697703
'V=1',
704+
'NDK_DEBUG=' + ("1" if self.build_as_debuggable else "0"),
698705
'APP_PLATFORM=android-' + str(self.ctx.ndk_api),
699706
'APP_ABI=' + arch.arch,
700707
*extra_args, _env=env

pythonforandroid/recipes/sdl2/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ def build_arch(self, arch):
2222
env = self.get_recipe_env(arch)
2323

2424
with current_directory(self.get_jni_dir()):
25-
shprint(sh.ndk_build, "V=1", _env=env)
25+
shprint(
26+
sh.ndk_build,
27+
"V=1",
28+
"NDK_DEBUG=" + ("1" if self.build_as_debuggable else "0"),
29+
_env=env
30+
)
2631

2732

2833
recipe = LibSDL2Recipe()

pythonforandroid/toolchain.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def build_dist_from_args(ctx, dist, args):
193193
ctx.recipe_build_order))
194194
info('Dist will also contain modules ({}) installed from pip'.format(
195195
', '.join(ctx.python_modules)))
196+
if args.build_mode == "debug":
197+
info('Building WITH debugging symbols (no --release option used')
198+
else:
199+
info('Building WITHOUT debugging symbols (--release option used)')
196200

197201
ctx.dist_name = bs.distribution.name
198202
ctx.prepare_bootstrap(bs)
@@ -204,6 +208,7 @@ def build_dist_from_args(ctx, dist, args):
204208
ignore_project_setup_py=getattr(
205209
args, "ignore_setup_py", False
206210
),
211+
debug_build=(args.build_mode == "debug"),
207212
)
208213

209214
ctx.bootstrap.run_distribute()
@@ -495,7 +500,8 @@ def add_parser(subparsers, *args, **kwargs):
495500
parser_apk.add_argument(
496501
'--release', dest='build_mode', action='store_const',
497502
const='release', default='debug',
498-
help='Build the PARSER_APK. in Release mode')
503+
help='Build your app as a non-debug release build. '
504+
'(Disables gdb debugging among other things)')
499505
parser_apk.add_argument(
500506
'--use-setup-py', dest="use_setup_py",
501507
action='store_true', default=False,
@@ -571,6 +577,8 @@ def add_parser(subparsers, *args, **kwargs):
571577
if hasattr(args, "private") and args.private is not None:
572578
# Pass this value on to the internal bootstrap build.py:
573579
args.unknown_args += ["--private", args.private]
580+
if args.build_mode == "release":
581+
args.unknown_args += ["--release"]
574582
if hasattr(args, "ignore_setup_py") and args.ignore_setup_py:
575583
args.use_setup_py = False
576584

@@ -944,7 +952,9 @@ def apk(self, args):
944952
with current_directory(dist.dist_dir):
945953
self.hook("before_apk_build")
946954
os.environ["ANDROID_API"] = str(self.ctx.android_api)
947-
build_args = build.parse_args(args.unknown_args)
955+
build_args = build.parse_args_and_make_package(
956+
args.unknown_args
957+
)
948958
self.hook("after_apk_build")
949959
self.hook("before_apk_assemble")
950960

@@ -994,7 +1004,9 @@ def apk(self, args):
9941004
gradle_task = "assembleRelease"
9951005
else:
9961006
raise BuildInterruptingException(
997-
"Unknown build mode {} for apk()".format(args.build_mode))
1007+
"Unknown release type {} for apk()".
1008+
format(args.build_mode)
1009+
)
9981010
output = shprint(gradlew, gradle_task, _tail=20,
9991011
_critical=True, _env=env)
10001012

0 commit comments

Comments
 (0)