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

Does Bazel support R8? #31

Open
tdounnyy opened this issue Dec 8, 2020 · 10 comments
Open

Does Bazel support R8? #31

tdounnyy opened this issue Dec 8, 2020 · 10 comments

Comments

@tdounnyy
Copy link

tdounnyy commented Dec 8, 2020

Didn't find any direct info to this.
If support, is there any guideline?
If not, is it on schedule?

I found a Bazel compile fail with Proguard 5.3.3, it would be nice if someone would share some suggestions.
https://stackoverflow.com/questions/65182300/bazel-build-android-demo-fail-with-proguard
Thank you

@nkoroste
Copy link
Contributor

nkoroste commented Mar 2, 2021

Any updates on this?
@jin can you help direct this to the right person?

@ahumesky
Copy link
Collaborator

Hi, the rules do not currently support R8. We'll be adding support, unfortunately I can't give a concrete timeline on that yet.

@paladine
Copy link

Any updates? Found a fatal proguard error in androidx.fragment:fragment:1.3.6

Error: Unknown option '-if' in line 16 of file 'bazel-out/android-armeabi-v7a-fastbuild/bin/external/maven/_aar/androidx_fragment_fragment/proguard.txt',
  included from argument number 22

The file contents are this:

# The default FragmentFactory creates Fragment instances using reflection
-if public class ** extends androidx.fragment.app.Fragment
-keepclasseswithmembers,allowobfuscation public class <1> {
  public <init>();
}

@mauriciogg
Copy link
Contributor

We have an internal implementation that enables R8 flag guarded behind a configuration flag (--experimental_enable_r8).
The change rewires the action graph when --experimental_enable_r8 is passed so that proguarding and dexing is all handled by R8 in a single action (from deploy jar to dex classes). All changes are in AndroidBinary (with exception of the flag which lives in AndroidConfiguration). The change also requires an additional binary (proguard_compat) passed via --proguard_top which knows how to invoke R8 correctly with the proguard specs. ATM we have only implemented native multidex (Android version L+ support).

We can contribute our implementation and the proguard_compat binary (thinking it could live in src/tools/android/java/com/google/devtools/build/android/r8/BUILD.tools). Does this sound reasonable or is there some ongoing work in the starlark rules that duplicates? This would also help the R8 team to contribute directly to bazel.
@timpeut @ahumesky

@mauriciogg
Copy link
Contributor

mauriciogg commented Feb 7, 2022

bazelbuild/bazel#14741 adds basic support for calling the R8.
Note that the implementation assumes the presence of a shim binary that translates the proguard command line to the proper r8 calls which is not in this pr but amounts to something like:
R8Command.Builder builder = R8Command.builder() .addProguardConfiguration(printConfig, Origin.root()) .addLibraryFiles(libraryJars) .addProgramFiles(input) .setMode(CompilationMode.RELEASE) .setOutput(output, OutputMode.DexIndexed) .setMinApiLevel(NATIVE_MULTIDEX_MIN_SDK);

@benjaminRomano
Copy link

benjaminRomano commented Feb 8, 2022

@mauriciogg can we create a gist that contains an example of the shim binary setup?

@benjaminRomano
Copy link

FYI @sgjesse here is the patch we've been using for R8 support in Bazel.

@sgjesse
Copy link

sgjesse commented Feb 8, 2022

FYI @ahumesky, @timpeut and @lizkammer well.

@mauriciogg
Copy link
Contributor

@mauriciogg can we create a gist that contains an example of the shim binary setup?

https://gist.github.com/mauriciogg/6e7217f03a19a40979f23ca1e5eff297

@cushon
Copy link
Contributor

cushon commented Apr 5, 2022

There's some related discussion about Bazel support for r8 in bazelbuild/bazel#14966 (comment)

copybara-service bot pushed a commit that referenced this issue Aug 22, 2023
bazelbuild/bazel#18239
#31
#105

PiperOrigin-RevId: 559196543
Change-Id: Id2a6aea5079a14f305ca48d79d292b166677befa
jylinv0 pushed a commit to jylinv0/rules_android that referenced this issue Jan 23, 2024
bazelbuild/bazel#18239
bazelbuild#31
bazelbuild#105

PiperOrigin-RevId: 559196543
Change-Id: Id2a6aea5079a14f305ca48d79d292b166677befa
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

No branches or pull requests

8 participants