Skip to content

DEV-1426: ShimmerCapture 1.3.5 runs R8; edge to edge via EdgeToEdge - #152

Open
MAzalya wants to merge 2 commits into
masterfrom
DEV-1426_r8_edge_to_edge
Open

MAzalya wants to merge 2 commits into
masterfrom
DEV-1426_r8_edge_to_edge

Conversation

@MAzalya

@MAzalya MAzalya commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Google Play's dashboard for ShimmerCapture 1.3.4 flagged one issue to fix by Feb 2027 and recommended two actions. This addresses the issue and the first recommendation, explains the second, and raises the app to 1.3.5 / versionCode 38.

1. "DEX code optimisation is below our threshold: Obfuscation (0%)": fixed

The release build now runs R8 (minifyEnabled true, proguard-android-optimize.txt). R8 breaks code that's found by name at runtime only, never at build time. So proguard-rules.pro keeps everything R8 can't see being used, each rule with its reason:

  • All Shimmer code, com.shimmerresearch.**: the driver, this library, the app, and the closed-source biophysical processing jar. It relies on:

    • Java serialization: devices are configured through serialized clones, and classes have private readObject/writeObject.
    • Reflection: ExGConfigBytesDetails.getExGConfigOptionFields() and UartPacketDetails.getUartPropertyParsed() collect static fields reflectively, so R8 would drop those fields as unused and the ExG option lists would come out short.

    Keeping it whole makes this safe without auditing every class. Optimising it can come later, one hardware-tested step at a time.

  • androidplot (its Configurator reflects on getter and setter names) and AndroidBluetoothLibrary (built on reflection).

  • Two AppCompat names MainActivity uses: Toolbar.mTitleTextView, read by reflection, and ActionMenuView, matched by class name, to align the toolbar. R8 would rename both, and the code's catch (Exception ignore) would hide the failure: the toolbar would just look slightly off.

  • -dontwarn for classes the driver refers to that were never in the app:

    • protobuf, Netty and JNA, excluded in the root build.gradle;
    • desktop UI (java.awt, javax.swing);
    • optional dependencies of gRPC, Netty and Guava.

    The code referring to them is Shimmer code, kept as-is, so the app behaves exactly as before.

Result: 5,332 of 6,680 classes are obfuscated, 79.8%; Play's threshold is 25%. The APK goes from 25.8 MB to 11.8 MB. I searched the app, the library and the driver at 0.11.12_beta for reflection and class-name checks into non-Shimmer code. The two AppCompat sites above are the only ones; the driver's one check is against a Shimmer class, which is kept.

Crash reports: the workflow keeps R8's mapping.txt as its own artifact, shimmercapture-mapping, and the play job uploads it with the APK, so Play's crash reports show real names. The release job publishes only shimmercapture-apk, so the mapping never reaches the public GitHub release.

2. "Edge-to-edge may not display for all users": fixed

MainActivity now uses EdgeToEdge.enable() (androidx.activity 1.8.0, already a dependency) instead of WindowCompat.setDecorFitsSystemWindows(…, false). It sets SystemBarStyle.dark(…) for the status bar, so the icons stay light over the toolbar, which is dark in both light and dark mode. The default would give dark icons in light mode. The existing inset listeners are unchanged.

3. "Your app uses deprecated APIs or parameters for edge-to-edge": not fixed here

Neither the app nor the library calls the deprecated APIs (setStatusBarColor, setNavigationBarColor, …). The likely sources are AppCompat/Material 1.12.0 and androidx.activity 1.8.0, which still call them internally. The versions that stop doing so need compileSdk 35+, which this repo's AGP 8.2.2 doesn't support, so the fix is a toolchain upgrade for the whole repo, every example and CI. Play Console lists the exact call sites under that recommendation: if they're all inside libraries, that upgrade is the fix and needs its own ticket.

Tested

On the Android 16 emulator (Pixel 7 and Pixel Tablet profiles), using the shrunk release APK itself, signed with a throwaway key:

Case Result
Fresh install, permission prompts granted by hand Launches, service starts, toolbar identical to the pre-R8 build (title and ⋮ alignment), light status bar icons
All 14 menu items present; the no-device actions (Disconnect All, Sampling Rate, Low Power, SD logging, Device Info, start/stop streaming) No crash
Connect → Scan Discovery runs
All five tabs, incl. Plot (androidplot renders) and Signals to Plot OK
Bluetooth off at launch, then Allow (DEV-1402's path) No crash; Bluetooth Manager created; Connect opens
Tablet, landscape and portrait, repeated rotation Same activity throughout, no WindowLeaked, layout as before
App log during all of it No ClassNotFoundException, NoSuchField/Method, InvalidClassException, NoClassDefFoundError

assembleRelease and assembleDebug pass.

Not yet tested: real hardware. Nothing above connects to a Shimmer, and that's where serialization (configuring through clones), the ExG options and streaming are exercised. Before release:

  1. Merge.
  2. Do a dry run, and install its APK (the shimmercapture-apk artifact, signed with the real key) on a phone, after uninstalling the Play version.
  3. Check the following on a Shimmer3, a Shimmer3R and a Verisense, over Bluetooth Classic and BLE:
    • connect; configure (sampling rate, sensors, ExG settings, device config);
    • stream and plot;
    • SD logging and CSV;
    • Verisense sync, erase and disable logging;
    • low power and device info.

RELEASING.md now says this: the debug build is never shrunk, so it can't show what R8 breaks.

Also

  • RELEASING.md: a new R8 section covering what's kept and why, what breaks and where, how to add a rule, and the mapping file. The failure table covers Missing classes detected while running R8 and a release-only crash.
  • AGENTS.md: a short note on R8.
  • Uprev: a separate commit, 1.3.5 / versionCode 38.
  • DEV-1427 (DEV-1427: ShimmerService works without a BluetoothManager throughout #151) touches ShimmerService and the fragments, not these files, so the two merge in either order.

🤖 Generated with Claude Code

MAzalya and others added 2 commits November 6, 2026 13:38
…ToEdge

Google Play flags 1.3.4: "DEX code optimisation is below our threshold:
Obfuscation (0%)", to fix by Feb 2027. The release build now runs R8
with proguard-android-optimize.txt.

proguard-rules.pro keeps all com.shimmerresearch code as it is (driver,
library, app, biophysical processing jar): it relies on Java
serialization (devices are configured through serialized clones,
private readObject/writeObject) and reflection (ExGConfigBytesDetails
and UartPacketDetails collect static fields reflectively). androidplot
and AndroidBluetoothLibrary work by reflection and are kept too, as are
the two AppCompat names MainActivity reaches by name to align the
toolbar (Toolbar.mTitleTextView, ActionMenuView), which R8 would rename
silently. -dontwarn covers what the driver refers to that the app never
had: protobuf, Netty and JNA (excluded in the build), desktop UI, and
optional gRPC/Netty/Guava dependencies. 79.8% of classes are
obfuscated (Play's threshold is 25%); the APK goes from 25.8 to 11.8 MB.

The workflow keeps R8's mapping.txt as its own artifact and the play
job uploads it, so Play's crash reports show real names; the release
job never publishes it.

MainActivity goes edge to edge with EdgeToEdge.enable() instead of
WindowCompat.setDecorFitsSystemWindows(), as Play recommends, with
light status bar icons over the always-dark toolbar.

RELEASING.md explains R8, what it breaks (at runtime only) and that the
dry run's APK, not the debug build, is what to test on hardware.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant