Improve get_apksigner_path() robustness #67668
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a few existing problems with signing with
apksigner
, all having to do with the fact that we currently just use the first one we find:apksigner
is for the Target SDKapksigner
is for a version below DEFAULT_TARGET_SDKapksigner
we chose is actually executable.The latter is a problem if the user has many versions of build-tools installed (which is very likely if you're an android developer), and if the user has a version of
build-tools
that requires Java <10 (-Djava.ext.dirs
was removed in Java 10). Since we currently just use the first one we find, it will be the lowest version number, which makes this more likely, andapksigner
will likely fail to execute. Build tools version 27 was the last version that required Java <10.So, this PR will trawl the versions in the directory, and it will choose one that matches the target sdk. If not, it chooses a version between 28 (or if the target sdk was manually set lower) and DEFAULT_TARGET_SDK. If it can't find any of those, it will use the first available.
It then checks all the versions it found, in order of ideal to worst, to see if they execute. Once one executes, it returns that path.
We don't check to see if it executes when we aren't actually exporting, because this can significantly slow down the UI if we do this.