-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
android_binary doesn't configure ProGuard/R8 for Android? #14909
Comments
Android ProGuard actions need to be able to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. This allows configurable access to those actions. Please see bazelbuild#14909 for context.
Android ProGuard actions need to be able to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. This allows configurable access to those actions. Please see bazelbuild#14909 for context.
Android ProGuard actions need to be able to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. This allows configurable access to those actions. Please see bazelbuild#14909 for context.
Android ProGuard actions need to be able to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. This allows configurable access to those actions. Please see bazelbuild#14909 for context.
Adds Android default ProGuard Specs to AndroidSdkProvider ...and uses them when ProGuarding an android_binary. Background: Android ProGuard actions need to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. Please see bazelbuild#14909 for more context.
I took a solid crack at part 1 of the fix (above) in #14910. Originally, I was thinking I'd just quickly add the configurations to an export_files. But then I decided that weaving them into the Android SDK Provider ( ...and then I figured I might as well just take a shot at part 2, too, since I'd made it easy :) For any Bazelers reading this, I'd love your review! |
Adds Android default ProGuard Specs to AndroidSdkProvider ...and uses them when ProGuarding an android_binary. Background: Android ProGuard actions need to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. Please see bazelbuild#14909 for more context.
Adds Android default ProGuard Specs to AndroidSdkProvider ...and uses them when ProGuarding an android_binary. Background: Android ProGuard actions need to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. Please see bazelbuild#14909 for more context.
Adds Android default ProGuard Specs to AndroidSdkProvider ...and uses them when ProGuarding an android_binary. Background: Android ProGuard actions need to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. Please see bazelbuild#14909 for more context.
Adds Android default ProGuard Specs to AndroidSdkProvider ...and uses them when ProGuarding an android_binary. Background: Android ProGuard actions need to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. Please see bazelbuild#14909 for more context.
Adds Android default ProGuard Specs to AndroidSdkProvider ...and uses them when ProGuarding an android_binary. Background: Android ProGuard actions need to use proguard-android-optimize.txt or proguard-android.txt to be configured properly. Please see bazelbuild#14909 for more context.
Cross-referencing and copy-pasting some discussion in #14910 about why android_binary doesn't configure proguard by default:
|
Hi, wonderful Bazel folks,
This issue is about ProGuard/R8 for
android_binary
, requiring also a minor change to theandroid_sdk_repository
rule. I think it's probably more bug than feature request. If I'm right, I'm guessing the fix shouldn't take too much time.The issue itself: It looks like android_binary might be forgetting to configure its ProGuard invocation for Android by not including the default Android configuration.
Background: For ProGuard/R8 to work properly for Android, one is supposed to supply the default Android ProGuard configuration file so things are set up to work properly. (For more, see https://developer.android.com/studio/build/shrink-code). I was looking closely at all this because I was building an extension to build, ProGuard, and distribute aars, which would solve #348. That meant I was reading the Android docs and looking at android_binary as a reference.
Evidence that makes me think Bazel isn't supplying this important configuration file:
bazel aquery "mnemonic('Proguard',deps(//:android_binary_target))"
, and examining the specs used didn't show any indication of using the Android configuration files.android_sdk_repository
.Expected behavior would be
android_binary
correctly, automatically configuring ProGuard/R8 for Android when it runs ProGuard. Or at least having android_sdk_repository expose the specs needed to manually do so.Suggested fix:
See https://android.googlesource.com/platform/tools/base/+/refs/heads/mirror-goog-studio-main/build-system/gradle-core/src/main/java/com/android/build/gradle/ProguardFiles.java
I don't see a good way of accessing that code through the SDK (I see neither gradle nor that class in a grep of the SDK's jars), so sadly, we'll probably need to bundle them separately, as Bazel does with ProGuard.
@androidsdk//:tools/proguard/proguard-android-optimize.txt
for opt builds and@androidsdk//:tools/proguard/proguard-android.txt
otherwise, just as an additional private attribute, and automatically added to the ProGuard configurations on the command line.Thanks!
Chris
(ex-Googler)
P.S. All testing was on bazel rolling, 6.0.0-pre.20220208.2.
The text was updated successfully, but these errors were encountered: