Skip to content

[draft] Android XML Views reference implementation + shared E2E matrix#286

Draft
Alex Freas (akfreas) wants to merge 32 commits into
mainfrom
android-xml-views-reference-impl
Draft

[draft] Android XML Views reference implementation + shared E2E matrix#286
Alex Freas (akfreas) wants to merge 32 commits into
mainfrom
android-xml-views-reference-impl

Conversation

@akfreas
Copy link
Copy Markdown
Collaborator

@akfreas Alex Freas (akfreas) commented May 25, 2026

Adds a legacy XML Views reference implementation for the Android SDK and re-runs the existing UI Automator suite against both the Compose impl and the new Views impl in parallel, mirroring the iOS swiftui/uikit + matrix CI pattern.

What's in this PR

  • com.contentful.optimization.views SDK adapterOptimizationManager, OptimizedEntryView, ScreenTracker, TrackingRecyclerView. Thin wrapper around the existing core API; no personalization or tracking logic lives here.
  • implementations/android-sdk/shared — new com.android.library module hosting AppConfig, ContentfulFetcher, EventStore, MockPreviewContentfulClient, RichText. Both :compose and :views depend on it.
  • implementations/android-sdk/compose — renamed from :app. Pure rename, no behavior change.
  • implementations/android-sdk/views — new com.android.application module with applicationId com.contentful.optimization.app.views. Mirrors every Compose screen/component with XML layouts and a per-View setTestTag helper that exposes the same kebab-case test ids to UI Automator.
  • Shared UI Automator suite parameterized by APP_PACKAGEAppLauncher reads the target package from InstrumentationRegistry.getArguments(); defaults to the Compose app so IDE runs keep working.
  • CI matrix — split the e2e-android-sdk job into a build-once stage (compose, views, uitests APKs) and a matrix-fanout stage that boots one emulator per app and runs the same uitests against each.

Test-id contract for XML Views

UI Automator's By.res("identify-button") matches AccessibilityNodeInfo.viewIdResourceName. Compose's testTagsAsResourceId = true writes the test tag verbatim there; XML android:id can't contain hyphens. The Views path uses an AccessibilityDelegateCompat that overrides viewIdResourceName to the kebab tag — and clears view.id to View.NO_ID first, because View.onInitializeAccessibilityNodeInfoInternal re-populates the field from Resources.getResourceName(mID) and clobbers the override on the CI x86_64 emulator. The helper also mirrors the test tag onto contentDescription so the shared TestHelpers.findElement By.res → By.desc fallback resolves the same selector.

Status

  • Compose leg: 56/58 passing in CI. The two failures (testScenario5ResettingSingleVariantOverrideRestoresVariant and testScenario3ResettingAudienceOverrideRestoresVariant in PreviewPanelOverridesTests) are pre-existing flakes that also fail on the final-mobile-sdk-fixes branch this PR builds on — not caused by anything in this PR.
  • Views leg: 56/58 passing in CI. Failures: testScenario3... (same pre-existing flake as Compose) plus testTracksEntryViewEventsForVisibleEntries in AnalyticsTests — the first entry's view-tracking component event isn't surfacing on CI's slow x86_64 headless emulator even though events for other entries do; passes locally on arm64. Worth a follow-up investigation.

Pre-existing CI gaps this PR also fixes

The Android CI job has been red on final-mobile-sdk-fixes for unrelated reasons that were masked by commit 6a596527 (the silent-pass guard). Bringing CI back to green required:

  • Drop set -o pipefail from the emulator-runner script — the action invokes the script via /usr/bin/sh -c, which errors with Illegal option -o pipefail and terminates the script before any test runs.
  • Drop the manual adb shell settings put global window_animation_scale 0 lines — the action's disable-animations: true already does this and the redundant adb commands exit non-zero on the freshly-booted API 35 image under the action's bash -e wrapper.
  • Use a workspace-relative android-apks/ directory for the build→matrix artifact handoff so actions/upload-artifact@v7 keys the in-zip paths off the LCA correctly.

🤖 Generated with Claude Code

Alex Freas (akfreas) and others added 30 commits May 22, 2026 13:19
…single @contentful/optimization-js-bridge under packages/universal that builds one shared src/index.ts into both native UMD bundles
…merged @contentful/optimization-js-bridge package
…imization-js-bridge so the JS bridge matches the iOS and Android native SDKs that already call them
… adapter on top of the existing core API so XML/Views-based Android apps can integrate the SDK without Compose dependencies
…ibrary module under com.contentful.optimization.shared so both the Compose reference impl and the upcoming XML Views impl can consume the same AppConfig, ContentfulFetcher, EventStore, MockPreviewContentfulClient, and RichText
…e and reroute every script, gradle build path, IDE run config, and CI workflow line to the new module so it sits as a sibling of the upcoming :views XML reference impl, mirroring the iOS swiftui/uikit pair
…se impl screen-for-screen, using OptimizedEntryView, ScreenTracker, and OptimizationManager from the new SDK views adapter and exposing every Compose testTag through an AccessibilityNodeInfoCompat.setViewIdResourceName helper so the shared UI Automator suite resolves the same selectors against both apps
…arguments so the same UI Automator suite can drive both the Compose reference impl and the new XML Views reference impl, defaulting to the Compose impl when no override is passed
…ws, build:apks) and teach scripts/run-e2e.sh to pick the gradle module + APK file + am instrument APP_PACKAGE arg from the APP_PACKAGE env var so the same script drives either reference impl
…ompose, views, and uitests APKs and a matrix-fanout stage that boots one emulator per app and runs the same UI Automator suite against each with APP_PACKAGE forwarded as an instrumentation argument, mirroring the iOS SwiftUI/UIKit dual-target CI pattern
…st-id contract, the APP_PACKAGE instrumentation argument, and the new com.contentful.optimization.views SDK adapter in the AGENTS.md files
…g AnalyticsTests against both apps: wait for client.isInitialized before driving consent/page so the profile state flow actually advances, memoize the OptimizedEntryView view-tracking controller on its (entry, personalization) tuple so personalization re-emissions don't reset the dwell timer, and tighten the entry content padding so the analytics block sits inside the viewport like it does in Compose; also fetch entries exactly once per Activity instead of re-rendering on every profile state change
…ity.onCreate after the reset-prefs check so cold launches with reset=true do not race against the bridge loading the persisted profile, gate the Views identify and reset button handlers behind client.isInitialized so a quick test tap before the bridge boots no longer no-ops, attach the preview-panel floating action button from the post-init coroutine to mirror OptimizationRoot's previewPanel config, derive the nested entry test tag from the resolved entry's sys.id so personalization-variant ids surface like they do on the Compose side, and force-stop both reference impls at the start of scripts/run-e2e.sh so local back-to-back runs against different apps cannot leak stale focused windows into the next instrumentation run
…nside LiveUpdatesTestActivity.loadEntry, force-close the preview panel on every entry into LiveUpdatesTestActivity so a prior testTogglePreviewPanel cannot leave shouldLive=true sticky for the next test's locked slots, and suppress the AccessibilityNodeInfoCompat ACTION_CLICK from TestTagging.setTestTag so the shared TestHelpers.tapElement helper's accessibility-then-coordinate double click does not double-fire onClick listeners on stock Android Buttons the way it would have to on Compose's debounced gesture handler
…x artifact handoff so actions/upload-artifact v7 keys the in-zip paths off the LCA correctly and the matrix leg's adb install lines find compose-debug.apk and views-debug.apk where they expect them
…rom the matrix script — the emulator-runner action already does this via disable-animations: true and the duplicate adb commands exit non-zero under the action's bash -e wrapper on the freshly-booted API 35 image, terminating the script before any apk install or instrument run
…okes it via /usr/bin/sh which errors out with 'Illegal option -o pipefail' on the first line, terminating the script before any apk install or instrument run. The grep checks on the test-output log already detect instrumentation failures regardless of pipe-status propagation
…too in setTestTag, so UiAutomator's By.desc fallback finds buttons in the CI x86_64 headless emulator config where the AccessibilityDelegate-driven viewIdResourceName override appears to not always propagate to the accessibility node tree on time
…n setTestTag right before installing the AccessibilityDelegate, so the framework's onInitializeAccessibilityNodeInfoInternal can't populate viewIdResourceName from Resources.getResourceName(mID) and clobber our delegate's setViewIdResourceName(testTag) before UiAutomator's By.res reads it on the CI x86_64 emulator. Compose's testTagsAsResourceId works because Compose nodes have no underlying XML id to conflict; this brings the Views path to the same precondition
…init renderer at declaration, mark afterEach as void, replace Object.create(null) cast with a type-predicate factory
…thResolvers in createDeferred, void the beforeEach/afterEach calls, init renderer at declaration, replace Object.create(null) cast with a type-predicate factory
…l and 0.4 ratio to named constants, destructure mock.mock.calls all the way through, init renderer at declaration, void the beforeEach/afterEach calls
… test: void the beforeEach call, extract the inner subscriber-notify forEach callback to a named arrow, capture the original destroy via Reflect.get with an explicit this-typed annotation to silence both prefer-destructuring and unbound-method
…eact-web test: add a void-this reference inside the mock destroy method to acknowledge class-methods-use-this, switch indexed array access to computed-key object destructuring
…r tests so they actually validate the mocked destroy/screen/states.eventStream shape at runtime instead of returning true unconditionally; the lint-clean type narrowing now matches what the runtime check claims
…ollView — the e2e Detox suite preview-panel-overrides.test.js was changed in 95d6afc to match the panel scroll container by that id but the SDK side of the rename never landed on final-mobile-sdk-fixes, so all 8 scenarios were failing with 'No views in hierarchy found matching: view.getTag() is preview-panel-scroll'
…eanup-order test that broke the CI Format Check; the cherry-picked lint commit was line-wrapped one way and prettier wants it the other way
…view panel and update Detox scenario 6 to tap by testID
…via sdk.page in the demo app so the override interceptor can be exercised end-to-end from Detox
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