From 34a98374b1878cb35f30b186604115465c5fddd2 Mon Sep 17 00:00:00 2001 From: Jonas Thiem Date: Sun, 16 Jun 2019 05:32:22 +0200 Subject: [PATCH] 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 :smile: - makes SDL2 and any standard `NDKRecipe` build with `NDK_DEBUG=1` when `--release` is not specified to add debugging symbols - fixes debugging symbols being stripped even when not using `--releaase` which makes using gdb a hassle --- .../bootstraps/common/build/build.py | 14 ++++++--- .../common/build/templates/build.tmpl.gradle | 6 ++++ pythonforandroid/bootstraps/sdl2/__init__.py | 3 +- .../build/templates/AndroidManifest.tmpl.xml | 1 + .../bootstraps/service_only/__init__.py | 3 +- .../bootstraps/webview/__init__.py | 3 +- pythonforandroid/build.py | 11 ++++--- pythonforandroid/recipe.py | 4 ++- pythonforandroid/recipes/sdl2/__init__.py | 7 ++++- pythonforandroid/toolchain.py | 20 +++++++++++-- tests/test_build.py | 29 +++++++++++++++++++ 11 files changed, 85 insertions(+), 16 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index ed5e708892..f32047d417 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -486,7 +486,8 @@ def make_package(args): "args": args, "service": service, "service_names": service_names, - "android_api": android_api + "android_api": android_api, + "debug": "debug" in args.build_mode, } if get_bootstrap_name() == "sdl2": render_args["url_scheme"] = url_scheme @@ -509,7 +510,8 @@ def make_package(args): aars=aars, jars=jars, android_api=android_api, - build_tools_version=build_tools_version + build_tools_version=build_tools_version, + debug_build="debug" in args.build_mode, ) # ant build templates @@ -574,7 +576,7 @@ def make_package(args): raise e -def parse_args(args=None): +def parse_args_and_make_package(args=None): global BLACKLIST_PATTERNS, WHITELIST_PATTERNS, PYTHON # Get the default minsdk, equal to the NDK API that this dist is built against @@ -674,6 +676,10 @@ def parse_args(args=None): default=join(curdir, 'whitelist.txt'), help=('Use a whitelist file to prevent blacklisting of ' 'file in the final APK')) + ap.add_argument('--release', dest='build_mode', action='store_const', + const='release', default='debug', + help='Build your app as a non-debug release build. ' + '(Disables gdb debugging among other things)') ap.add_argument('--add-jar', dest='add_jar', action='append', help=('Add a Java .jar to the libs, so you can access its ' 'classes with pyjnius. You can specify this ' @@ -817,4 +823,4 @@ def _read_configuration(): if __name__ == "__main__": - parse_args() + parse_args_and_make_package() diff --git a/pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle b/pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle index 32bd091b72..a77f4b22b9 100644 --- a/pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle +++ b/pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle @@ -31,6 +31,12 @@ android { versionName '{{ args.version }}' } + {% if debug_build -%} + packagingOptions { + doNotStrip '**/*.so' + } + {%- endif %} + {% if args.sign -%} signingConfigs { release { diff --git a/pythonforandroid/bootstraps/sdl2/__init__.py b/pythonforandroid/bootstraps/sdl2/__init__.py index dde5f7f79b..99b8779ffa 100644 --- a/pythonforandroid/bootstraps/sdl2/__init__.py +++ b/pythonforandroid/bootstraps/sdl2/__init__.py @@ -47,7 +47,8 @@ def run_distribute(self): with open('blacklist.txt', 'a') as fileh: fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n') - self.strip_libraries(arch) + if not self.ctx.build_as_debuggable: + self.strip_libraries(arch) self.fry_eggs(site_packages_dir) super(SDL2GradleBootstrap, self).run_distribute() diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml index 119a4daefd..95450fe1b8 100644 --- a/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml @@ -52,6 +52,7 @@ An example Java class can be found in README-android.txt -->