bazelbuild / bazelbuild/rules_android

Idea from Firebase for Automatically Creating NDK/JNI ProGuard Specs

Open
#307 0 comments 2 reactions 0 assignees View on GitHub
P2
Dominant language
Java
Stars
203
Forks
95
PR merge metrics
No merged PRs in 30d

Description

Hi wonderful Bazel folks,

This is a feature request for the Android rules (+ maybe Java) based on a clever build trick I'd seen over at Firebase.

In a sentence: Eliminate a whole class of JNI issues by automatically keeping Java methods/classes called from C from being stripped by ProGuard.

Problem: When using the NDK, you inevitably end up needing to make calls into Java over the JNI. So you useProGuard specs (or @Keep annotations) to keep the Java APIs from being stripped. But now you have two sources of truth: The C code that makes the calls and the ProGuard specs (or annotations). When they inevitably get out of sync, you get runtime errors that can be rather hard to find--and you're always bothered, thinking to yourself that better build tooling could certainly have detected that at compile time.

A clever solution I saw over at Firebase: Have a little bit of infrastructure to make JNI calls easy. Then run `strings` on the native code, autodetecting the methods/classes you call over JNI, and generating proguard specs to keep them. Beautiful. Here's a [pointer into their source where it happens](https://github.com/firebase/firebase-cpp-sdk/blob/1d1bba1da2b9c5668b3e5cd1b583dd81dbfbe445/android_build_files/generate_proguard.gradle).

[This is probably less important than, e.g., bazelbuild/bazel#11497, which stops Bazel android rules from being useful for deploying Android Apps, but I still thought it might bet interesting long term. And maybe make someone smile with the cleverness of the Firebase folks.]

Cheers,
Chris

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the referenced Firebase file, android_build_files/generate_proguard.gradle, to understand the proposed JNI and ProGuard behavior, then locate the corresponding Android rules integration points. Done would require an agreed design and implementation that automatically generates keep specifications from native JNI references, with validation for the resulting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, java
Domain
build-system, mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.