Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .github/workflows/integration-tests-nav3-r8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Nav3 Built-in Back Stack Mappers R8 Check

# Verifies behavior of BackStackEntryMapper.SerialName from sentry-android-navigation3 in
# R8-minified builds on an emulator. Runs tests in:
#
# - R8 full mode against the compile floor of kotlinx-serialization-core and its latest stable
# release; and
# - R8 compat mode against the compile floor.
#
# Also runs all the module's unit tests against the latest stable release. See
# sentry-android-integration-tests/nav3-built-in-back-stack-mappers-r8-check/README.md.

# Only runs for the paths below. Not a required check, so skipped runs don't block PRs. Catalog
# filters match whole files, including changes to unrelated dependencies.
on:
push:
branches:
- main

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workflow omits 9.x.x branch

Medium Severity

The new workflow's on.push.branches lists main only. Maintenance-branch pushes to 9.x.x never run this R8 check, and the same main-only filter is the pattern that leaves 9.x.x PRs stuck on required status checks.

Fix in Cursor Fix in Web

Triggered by learned rule: No actions/checkout submodules

Reviewed by Cursor Bugbot for commit be9abcb. Configure here.

paths: &nav3-r8-paths
- 'sentry-android-navigation3/**'
- 'sentry-android-integration-tests/nav3-built-in-back-stack-mappers-r8-check/**'
# The settings, build script, and properties of the build that produces the check's APKs.
- 'sentry-android-integration-tests/*.gradle.kts'
- 'sentry-android-integration-tests/*.properties'
- 'scripts/test-nav3-built-in-back-stack-mappers-r8.sh'
- '.github/workflows/integration-tests-nav3-r8.yml'
# Build settings, R8 flags, build logic, the Gradle version, and the version catalogs
# (Kotlin, AGP and its R8, Compose, Nav3, and the kotlinx.serialization matrix).
- 'gradle.properties'
- 'settings.gradle.kts'
- 'build.gradle.kts'
- 'gradle/wrapper/**'
- 'gradle/libs.versions.toml'
- 'gradle/dependency-matrix.versions.toml'
- 'buildSrc/**'
- 'build-logic/**'
# Utilities the mapper uses to handle exceptions.
- 'sentry/src/main/java/io/sentry/util/**'
pull_request:
paths: *nav3-r8-paths

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
APK_DIR: "nav3-r8-check-apks"
APK_ARTIFACT_NAME: "nav3-r8-check-apks"

jobs:
# Runs separately from the APK builds, so a unit test failure doesn't hide the R8 check's results.
unit-tests:
name: Unit tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Java
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
distribution: 'temurin'
java-version: '21'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1

# Apps may ship a newer kotlinx.serialization than sentry-android-navigation3 compiles
# against. The Build workflow runs the unit tests against the floor.
- name: Run unit tests against the latest stable kotlinx.serialization
run: ./gradlew :sentry-android-navigation3:testReleaseUnitTest -Pnav3TestKotlinx=latestStable

build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Java
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
distribution: 'temurin'
java-version: '21'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1

- name: Build APKs
run: ./scripts/test-nav3-built-in-back-stack-mappers-r8.sh build "${{ env.APK_DIR }}"

- name: Upload APK artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: ${{ env.APK_ARTIFACT_NAME }}
path: ${{ env.APK_DIR }}
retention-days: 1

# Run on API 23, Nav3's minSdk, to verify that the minified app and its dependencies work on the
# oldest supported runtime.
run:
name: Run on API Level 23
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Download APK artifact
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: ${{ env.APK_ARTIFACT_NAME }}
path: ${{ env.APK_DIR }}

- name: Run check
uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # pin@v2.38.0
with:
api-level: 23
target: google_apis
arch: x86_64
disable-animations: true
disable-spellchecker: true
emulator-options: -memory 4096 -no-window -gpu auto -noaudio -no-boot-anim -camera-back none -no-snapshot-save
script: ./scripts/test-nav3-built-in-back-stack-mappers-r8.sh run "${{ env.APK_DIR }}"
123 changes: 123 additions & 0 deletions scripts/test-nav3-built-in-back-stack-mappers-r8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env bash
# Verifies BackStackEntryMapper.SerialName in R8-minified builds on a booted emulator or device.
# See sentry-android-integration-tests/nav3-built-in-back-stack-mappers-r8-check/README.md.
#
# Usage:
# test-nav3-built-in-back-stack-mappers-r8.sh Build all APKs, then run them.
# test-nav3-built-in-back-stack-mappers-r8.sh build DIR Build all APKs into DIR.
# test-nav3-built-in-back-stack-mappers-r8.sh run DIR Install and run every APK built into DIR.
set -euo pipefail

module="nav3-built-in-back-stack-mappers-r8-check"
moduleDir="sentry-android-integration-tests/nav3-built-in-back-stack-mappers-r8-check"
appId="io.sentry.tests.nav3.r8"
tag="NAV3_R8_CHECK"

copyApk() {
cp "${moduleDir}/build/outputs/apk/release/nav3-built-in-back-stack-mappers-r8-check-release.apk" "$1"
}

# Prints the subdirectory of DIR $1 that holds this script's APKs.
apkDirIn() {
echo "$1/${module}"
}

build() {
local outDir
outDir="$(apkDirIn "$1")"
mkdir -p "$outDir"
# Otherwise run() would also run APKs for versions no longer tested.
rm -f "$outDir"/*.apk
for mode in full compat; do
local fullMode=true
[[ "$mode" == "compat" ]] && fullMode=false
echo "Building R8 $mode mode APK (kotlinx floor)..."
./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" "-Pandroid.enableR8.fullMode=${fullMode}"
copyApk "${outDir}/${mode}.apk"

# Compat mode keeps more than full mode, so it's only tested with the floor, where it changes
# the outcome for named companion objects (kotlinx.serialization's own R8 rules only cover them
# from 1.10.0 on).
[[ "$mode" == "compat" ]] && continue

echo "Building R8 $mode mode APK (kotlinx latestStable)..."
./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" \
"-Pandroid.enableR8.fullMode=${fullMode}" "-Pnav3CheckKotlinx=latestStable"
copyApk "${outDir}/${mode}-kotlinx-latestStable.apk"
done
}

# Installs and launches APK $1, prints its check's output, and fails unless the check passed.
runApk() {
local apk="$1"
adb uninstall "$appId" > /dev/null 2>&1 || true
adb install "$apk" > /dev/null || return 1
# Reads only this launch's lines, so the previous APK's RESULT=PASS can't hide a failure. The
# timestamp has second precision, hence the sleep.
local since
sleep 1
since="$(adb shell "date +'%m-%d %H:%M:%S.000'" | tr -d '\r')" || return 1
adb shell am start -W -n "${appId}/.BuiltInBackStackMappersActivity" > /dev/null || return 1

local output=""
for _ in $(seq 1 60); do
output="$(adb logcat -d -T "$since" -s "${tag}:I" | grep "${tag}" || true)"
if grep -q "RESULT=" <<< "$output"; then
break
fi
if adb logcat -d -T "$since" -b crash | grep -q "$appId"; then
break
fi
sleep 1
done

if [[ -n "$output" ]]; then
sed -E "s/^.*${tag}: //" <<< "$output"
fi
if ! grep -q "RESULT=PASS" <<< "$output"; then
adb logcat -d -T "$since" -b crash | grep -A 20 "$appId" || true
return 1
fi
}

run() {
local apkDir
apkDir="$(apkDirIn "$1")"
local failed=0
shopt -s nullglob
local apks=("$apkDir"/*.apk)
if [[ ${#apks[@]} -eq 0 ]]; then
echo "No APKs found in $apkDir"
exit 1
fi

for apk in "${apks[@]}"; do
local name
name="$(basename "$apk" .apk)"
echo "=== $name"
if ! runApk "$apk"; then
echo "FAILED: $name"
failed=1
fi
done

if [[ $failed -ne 0 ]]; then
echo "Nav3 Built-in Back Stack Mappers R8 check failed."
exit 1
fi
echo "Nav3 Built-in Back Stack Mappers R8 check passed."
}

case "${1:-}" in
build) build "${2:?Usage: $0 build DIR}" ;;
run) run "${2:?Usage: $0 run DIR}" ;;
"")
apkDir="${moduleDir}/build/r8-check-apks"
build "$apkDir"
run "$apkDir"
;;
*)
echo "Usage: $0 [build DIR | run DIR]"
exit 1
;;
esac
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# nav3-built-in-back-stack-mappers-r8-check

Checks that `BackStackEntryMapper.SerialName` works after R8 obfuscation:

- The names and `unknown_entry_reason`s that `SentryNavEffect` records in the `Navigation` context match expectations.
- The compatibility probe succeeds conclusively.
- R8 actually obfuscates a representative class.

The app uses kotlinx.serialization's consumer rules and its own `proguard-rules.pro`; the SDK supplies no keep rules for app serialization
classes.

## Run

Boot an emulator or device, then run:

```bash
./scripts/test-nav3-built-in-back-stack-mappers-r8.sh
```

Versions come from `gradle/dependency-matrix.versions.toml`. Both floor and latestStable run in R8 full mode; floor also runs in compat mode
to cover older named-companion rules. Each APK must report `RESULT=PASS`.

CI also runs the module's unit tests against latestStable.

## Handle a failing update

Dependabot updates `kotlinxSerialization-latestStable` after a three-day cooldown.

**Compilation failure:** if the release requires newer Kotlin, leave the PR open, file a linked Kotlin upgrade issue, and merge after the
upgrade and passing checks. Closing the PR tells Dependabot to ignore that version. The release remains untested here; apps with newer
compilers may still work.

**Test failure:** investigate changes to serializer lookup, serial descriptors, or R8 rules. Fix incorrect names or unexpected `/unknown`
results, then merge the fix with the update.

Preserve support for the floor in either case; see "Version floor" in the `kotlinx` package README.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Checks BackStackEntryMapper.SerialName in R8-minified release builds. See README.md.
plugins {
id("com.android.application")
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
id("io.sentry.spotless")
id("io.sentry.jdk-target")
}

val sentryVersion = libs.versions.sentry.get()

// Defaults to the oldest supported version, which has the fewest R8 rules. The test script also
// runs with -Pnav3CheckKotlinx=latestStable.
val kotlinxVersion =
when (val role = providers.gradleProperty("nav3CheckKotlinx").getOrElse("floor")) {
"floor" -> matrixLibs.versions.kotlinxSerialization.floor.get()
"latestStable" -> matrixLibs.versions.kotlinxSerialization.latestStable.get()
else -> error("nav3CheckKotlinx must be floor or latestStable, but was $role.")
}

// kotlinx.serialization 1.10.0+ supplies R8 rules for named companions, so naming must succeed
// without app keep rules. Older releases may return the name or /unknown, depending on R8.
val namedCompanionAlwaysNamed =
kotlinxVersion.split('.', '-').let { parts ->
val major = parts[0].toInt()
val minor = parts.getOrNull(1)?.toIntOrNull() ?: 0
major > 1 || (major == 1 && minor >= 10)
}

android {
namespace = "io.sentry.tests.nav3.r8"
compileSdk = libs.versions.compileSdk.get().toInt()
compileSdkMinor = libs.versions.compileSdkMinor.get().toInt()

defaultConfig {
applicationId = "io.sentry.tests.nav3.r8"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
buildConfigField("boolean", "NAMED_COMPANION_ALWAYS_NAMED", "$namedCompanionAlwaysNamed")
}

signingConfigs {
getByName("debug") {
storeFile = file("../../debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
signingConfig = signingConfigs.getByName("debug")
}
}

buildFeatures {
buildConfig = true
compose = true
}

androidComponents.beforeVariants { it.enable = it.buildType == "release" }
}

dependencies {
implementation("io.sentry:sentry-android-navigation3:$sentryVersion")
// Lets the check initialize Sentry with a logger that records the mapper's messages.
implementation("io.sentry:sentry-android-core:$sentryVersion")
// compileOnly in sentry-android-navigation3; always available for apps that use Nav3.
implementation(libs.androidx.compose.runtime)
// Hosts SentryNavEffect, so the check reads names and reasons from what the SDK records. Compose
// UI 1.7+ provides the LocalLifecycleOwner the effect reads, as it does in every Nav3 app.
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.ui)

// Strict, so that no other dependency can raise the version the check runs against.
implementation(matrixLibs.kotlinxSerialization.core) { version { strictly(kotlinxVersion) } }
}
Loading
Loading