Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overriding debuggable in AndroidManifest #13801 #238

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EdbertChan
Copy link

@EdbertChan EdbertChan commented Jun 5, 2024

Background

Similar to bazelbuild/bazel#13801, the only way to get a non debuggable-apk debuggable="false" is to use --compilation-mode opt which will invalidate the entire dep graph.

Changes

The drawback of this diff is that unlike what exists in Bazel upstream, the source of truth for the "debuggable" flag of the AAPT2 command is not what is in the AndroidManifest.xml itself but whatever is in manifest_values in the BUILD file.

If no value, we fallback to the compilation-mode opt behavior.

Usage

android_binary(
    name = "app",
    dex_shards = 10,
    manifest = "src/bazel/AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "19",
        "appName": "...",
        "applicationId": "...",
        "debuggable": "false",
    },
    multidex = "native",
    visibility = ["//visibility:public"],
    deps = ["..."],
)

@EdbertChan
Copy link
Author

Per @restingbull (Corbin) offline conversation, the dependency on Compilation.OPT was a matter of convenience from inside of Google. Supposedly, few/nobody who was working on building with the debuggable flag build cared about release so full invalidation was not a problem.

If you weren't building an optimized binary, you should not be building a release anyway since release should be optimized.

Outside of Google, that may not be the case. Some developers very specifically want to work on performance.

@ted-xie
Copy link
Contributor

ted-xie commented Oct 17, 2024

Hey @EdbertChan, now that starlarkification + tools migration are done, I think we have the bandwidth to try out this CL internally. Could you rebase your fork so that the (now-fixed) BazelCI presubmit can run again?

@EdbertChan
Copy link
Author

@ted-xie Looks like they passed

Copy link
Contributor

@ted-xie ted-xie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EdbertChan I'm looking a bit more closely at this now. I have two thoughts right now:

  1. What happens if someone does bazel build //:app -c dbg with manifest_values = {debuggable: false} or vice versa, bazel build //:app -c opt with manifest_values = {debuggable: true}? In the first scenario, you'd have an un-debuggable debug app, and in the second scenario, you'd potentially be releasing a debuggable app, which opens doors for vulnerabilities. These were previously impossible scenarios that now become possible with this PR. I think we should either fail() in these scenarios, or at least issue a warning.
  2. Changing the existing behavior of blaze build -c opt/dbg with manifest_values[debuggable] could potentially be a complicated migration internally, so it would be preferrable to gate this behind a starlark flag.

@@ -735,6 +735,7 @@ def _package(
resource_files_zip = ctx.actions.declare_file(
"_migrated/" + ctx.label.name + "_files/resource_files.zip",
)
debug = utils.get_bool(manifest_values["debuggable"]) if "debuggable" in manifest_values else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a more descriptive name here, like manifest_values_debuggable.

@@ -773,7 +774,7 @@ def _package(
aapt = aapt,
busybox = busybox,
host_javabase = host_javabase,
debug = compilation_mode != _compilation_mode.OPT,
debug = compilation_mode != _compilation_mode.OPT if debug == None else debug,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two-step boolean logic split between line 738 and 777 is a little hard to follow; the ternary logic and inline if-statement here make it even harder. Can we consolidate this a little bit, like:

# line 738
manifest_values_debuggable = utils.get_bool(manifest_values["debuggable"]) if "debuggable" in manifest_values else None
dbg_compilation_mode = compilation_mode != _compilation_mode.OPT
app_debuggable = dbg_compilation_mode if manifest_values_debuggable == None else manifest_values_debuggable

# line 777-ish
debug = app_debuggable

@ted-xie ted-xie force-pushed the debuggable_manifest branch from 97459db to 7959ac3 Compare January 27, 2025 17:12
@ted-xie
Copy link
Contributor

ted-xie commented Jan 27, 2025

@EdbertChan I had some spare cycles and ended up adding the extra flag along with its plumbing. From a very quick ad hoc test, it seems to work on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants