Skip to content

[Due for payment 2026-11-04] [$175] [Sentry: APP-MD4] HybridApp Android: startup abort, "Cannot find native module 'ExpoAudio'" #104503

Closed

Description

@mountiny

Sentry

https://expensify.sentry.io/issues/APP-MD4

Impact (snapshot at filing)

  • Users (total since first seen): 31
  • Events: 32
  • Users (last 14d, all versions): 15
  • Users (last 14d, production 9.5.11 to 9.5.13): 4
  • First seen: 2026-09-22 (about 4 weeks ago)
  • Last seen: 2026-10-20 (ongoing)
  • Platform: Android HybridApp
  • App version(s): 9.4.88-0 to 9.5.12-1, spread across builds (1 to 3 users each)
  • Affected route(s) (parameterized): none. The crash happens while the JS bundle loads, before any screen renders.
  • Mechanism: TombstoneMerged (SIGABRT), level fatal

Stack trace (top frames, first-party only)

com.facebook.react.common.JavascriptException: [runtime not ready]: Error: Cannot find native module 'ExpoAudio'
  requireNativeModule
  metroRequire chain (module initialization while the bundle loads)
  global
facebook::react::JsErrorHandler::handleErrorWithCppPipeline (JsErrorHandler.cpp:403)
facebook::react::ReactInstance::loadScript lambda (ReactInstance.cpp:268)
std::terminate -> abort (SIGABRT)

Suspected cause

src/libs/Sound/index.native.ts imports expo-audio and calls setAudioModeAsync when the module loads. Startup code imports it (for example src/libs/actions/App.ts), so the bundle needs the ExpoAudio native module during its first evaluation. On some HybridApp Android launches that module is not registered, so requireNativeModule throws before the runtime is ready and the app aborts.

Reproduction

Unknown. See the Sentry events linked from the Sentry issue.

Related

  • Sibling Sentry IDs: none confirmed
  • Prior GH issues: none found
Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. self-assigned this
    on Oct 20, 2026
  2. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 20, 2026
  3. melvin-bot commented on Oct 20, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (External)

  4. changed the title [-][Sentry: APP-MD4] HybridApp Android: startup abort, "Cannot find native module 'ExpoAudio'"[/-] [+][$175] [Sentry: APP-MD4] HybridApp Android: startup abort, "Cannot find native module 'ExpoAudio'"[/+] on Oct 20, 2026
  5. melvin-bot commented on Oct 20, 2026

    @melvin-bot
  6. juni2003 commented on Oct 20, 2026

    @juni2003

    Contributor details
    Your Expensify account email: juni.xatti@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01867ae3203c9b7815?mp_source=share

    Proposal

    Please re-state the problem that we are trying to solve in this issue.
    On Android HybridApp builds, the app crashes instantly on startup with a fatal Cannot find native module 'ExpoAudio' error because the audio module is being invoked before the native runtime is fully ready.

    What is the root cause of that problem?
    The root cause is a synchronous, top-level execution of a native module method during the initial JS bundle evaluation.

    1. In src/libs/Sound/index.native.ts, expo-audio (or expo-av) is imported and configured (via setAudioModeAsync) at the top-level scope of the file.
    2. Because Sound is imported early in the app lifecycle (e.g., through src/libs/actions/App.ts), the JS engine evaluates this file synchronously during bundle load.
    3. In the Android HybridApp environment, native module registration timings differ from standalone React Native apps. Accessing the ExpoAudio native module at the top level throws a fatal JavascriptException because requireNativeModule fires before the HybridApp has finished registering it, causing a SIGABRT startup abort.

    What changes do you think we should make in order to solve the problem?
    We need to defer the native audio initialization so it does not execute during the top-level bundle evaluation. We will lazily configure the audio mode only when a sound is actually about to be played, wrapped in a safety catch for the HybridApp context.

    // src/libs/Sound/index.native.ts
    // ... existing imports ...
    
    let isAudioConfigured = false;
    
    function configureAudio() {
        if (isAudioConfigured) {
            return;
        }
        try {
            Audio.setAudioModeAsync({
                playsInSilentModeIOS: true,
                // ... existing configuration ...
            });
            isAudioConfigured = true;
        } catch (error) {
            Log.hmmm('Failed to initialize ExpoAudio in HybridApp', {error});
        }
    }
    
    export default function playSound(soundFile) {
        configureAudio(); // Defer native module access until runtime
        // ... existing play logic ...
    }

    What alternative solutions did you explore? (Optional)
    A purely native alternative would be patching the Android HybridApp host code to ensure the ExpoAudio package is forced into the synchronous native PackageList before the JS engine boots. This was rejected because React Native best practices dictate that JS should never assume native modules are synchronously available at bundle-load time. Lazy-loading the initialization in JS is much safer, prevents brittle startup crashes, and keeps the fix entirely within the cross-platform codebase.

  7. melvin-bot commented on Oct 20, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  8. taieddie commented on Oct 20, 2026

    @taieddie

    Contributor details
    Your Expensify account email: taieddie8@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01af851c9a7f771775

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    HybridApp on Android crashes during startup with a fatal SIGABRT because the JS bundle fails during evaluation with Cannot find native module 'ExpoAudio'.

    What is the root cause of that problem?

    In src/libs/Sound/index.native.ts, line 9 statically imports createAudioPlayer and setAudioModeAsync from expo-audio, while line 25 immediately calls setAudioModeAsync during top-level bundle evaluation. The entry point of expo-audio evaluates AudioModule, which directly executes requireNativeModule('ExpoAudio'). Because startup code like src/libs/actions/App.ts imports src/libs/Sound, this executes before the native module registry is available in HybridApp Android, causing an unhandled synchronous exception.

    What changes do you think we should make in order to solve the problem?

    1. In src/libs/Sound/index.native.ts, retain only the type-only import import type {AudioSource} from 'expo-audio' at the module root, removing the value import of createAudioPlayer and setAudioModeAsync.
    2. Remove the top-level evaluation of setAudioModeAsync at line 25.
    3. Keep the existing guard order in playSound: check getIsMuted(), then verify SOUND_ASSETS[soundFile].
    4. Inside playSound, dynamically require expo-audio wrapped in a try/catch block. If the native module cannot be resolved or loaded, log a warning and return early without throwing.
    5. In the same lazy execution path, configure audio mode on first use via setAudioModeAsync({playsInSilentMode: false, shouldPlayInBackground: false, interruptionMode: 'mixWithOthers'}). If configuration fails, catch the error, reset any memoized state to avoid poisoning future attempts, and return before creating the audio player.
    6. Guard player creation and playback with try/catch to ensure sound failures fail silently without crashing the app.

    What alternative solutions did you explore? (Optional)

    Earlier proposals failed by only moving setAudioModeAsync into a lazy helper while leaving the static value import import {createAudioPlayer, setAudioModeAsync} from 'expo-audio' at module scope. This still crashes on bundle load because expo-audio executes requireNativeModule('ExpoAudio') immediately upon being imported. Deferring the runtime require entirely prevents the startup abort. It fails safely.

  9. melvin-bot commented on Oct 20, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  10. haiquywork commented on Oct 21, 2026

    @haiquywork

    Proposal

    What is the root cause of that problem?

    src/libs/Sound/index.native.ts statically imports expo-audio and also calls setAudioModeAsync at module top level. expo-audio runs requireNativeModule('ExpoAudio') as soon as it is evaluated. @libs/Sound is imported by startup code such as src/libs/actions/App.ts and Session/index.ts, so that native lookup happens during the first bundle evaluation. If the native module isn't registered yet in a HybridApp launch, the error is thrown with no handler and the app aborts. Sound is not needed to start the app, but it can currently crash it.

    import {createAudioPlayer, setAudioModeAsync} from 'expo-audio';
    import {getIsMuted, SOUNDS, withMinimalExecutionTime} from './BaseSound';
    // Sound assets are statically imported for bundling.
    const SOUND_ASSETS = {
    [SOUNDS.DONE]: doneSound,
    [SOUNDS.SUCCESS]: successSound,
    [SOUNDS.ATTENTION]: attentionSound,
    [SOUNDS.RECEIVE]: receiveSound,
    } satisfies Record<ValueOf<typeof SOUNDS>, Extract<AudioSource, number | string>>;
    // Configure audio mode for in-app notification sounds:
    // - playsInSilentMode: false — respect the device's silent/mute switch (iOS)
    // - shouldPlayInBackground: false — push notification sounds are played by the system
    // - interruptionMode: 'mixWithOthers' — don't interrupt other audio (e.g. music)
    const audioModeConfigured = setAudioModeAsync({playsInSilentMode: false, shouldPlayInBackground: false, interruptionMode: 'mixWithOthers'});

    import {clearSoundAssetsCache} from '@libs/Sound';

    What changes do you think we should make in order to solve the problem?

    • In src/libs/Sound/index.native.ts, remove the runtime import of expo-audio (keep import type only) and remove the top-level setAudioModeAsync call.
    • Add a small lazy loader that runs on first play. It loads expo-audio with a dynamic import() inside try/catch, caches the result, and calls setAudioModeAsync once. The cached promise replaces audioModeConfigured.
    let audioPromise: Promise<typeof import('expo-audio') | null> | undefined;
    function loadAudio() {
        audioPromise ??= import('expo-audio')
            .then(async (m) => { await m.setAudioModeAsync({...}); return m; })
            .catch(() => null);
        return audioPromise;
    }
    • In playSound, call await loadAudio(). If it returns null, return silently, and log it with Log.warn. Otherwise use createAudioPlayer from the loaded module.
    • The existing getIsMuted check and the withMinimalExecutionTime wrapper stay as they are.
    • Add a unit test in tests/unit that mocks expo-audio to throw on load. It checks that importing @libs/Sound does not throw and that playSound resolves without error. A second test checks that audio mode is configured once, before the first player is created.

    What alternative solutions did you explore? (Optional)

    • Wrap the top-level import in try/catch with require. This works, but it still does native lookups at startup and it is harder to type than a lazy loader.
    • Fix the native HybridApp module registration. That is probably the deeper reason the module goes missing, but it can't be reproduced here. The JS side should not crash the app over a notification sound either way.
  11. jloa-dev commented on Oct 21, 2026

    @jloa-dev

    Contributor details
    Your Expensify account email: jloa.dev@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0163955a2ba221e513

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    HybridApp on Android crashes during application startup with a fatal SIGABRT / Tombstone crash:
    com.facebook.react.common.JavascriptException: [runtime not ready]: Error: Cannot find native module 'ExpoAudio'
    thrown while the JS bundle is being evaluated during ReactInstance::loadScript.

    What is the root cause of that problem?

    1. In src/libs/Sound/index.native.ts, line 9 statically imports createAudioPlayer, setAudioModeAsync from expo-audio:
      import {createAudioPlayer, setAudioModeAsync} from 'expo-audio';
      And line 25 immediately invokes native module initialization at the module top level:
      const audioModeConfigured = setAudioModeAsync({playsInSilentMode: false, shouldPlayInBackground: false, interruptionMode: 'mixWithOthers'});
    2. Core startup modules, including src/libs/actions/App.ts and src/libs/actions/Session/index.ts, import {clearSoundAssetsCache} from '@libs/Sound'. Therefore, Sound/index.native.ts is evaluated immediately when Metro loads and runs the initial JS bundle.
    3. During the initial script evaluation on Android HybridApp launches, requireNativeModule('ExpoAudio') is invoked synchronously before the native JSI/modules runtime is fully ready and registered.
    4. Because the error occurs at module top-level during bundle evaluation (ReactInstance::loadScript), it cannot be caught by any React ErrorBoundary, triggering facebook::react::JsErrorHandler::handleErrorWithCppPipeline and terminating the process via std::terminate -> abort() (SIGABRT).

    What alternative solutions did you explore? (Optional)

    Calling setAudioModeAsync inside an App.ts lifecycle hook was explored, but static imports of expo-audio still trigger module-level initialization code in expo-audio/src/index.ts. Lazy dynamic import (import('expo-audio')) on demand when sound is actually requested completely isolates startup from audio native module readiness.

    What changes do you think we should make in order to solve the problem?

    In src/libs/Sound/index.native.ts:

    1. Remove the static import of expo-audio (createAudioPlayer, setAudioModeAsync).
    2. Remove top-level invocation const audioModeConfigured = setAudioModeAsync(...).
    3. Lazily initialize and cache the audio mode and player on demand with graceful fallback:
    --- a/src/libs/Sound/index.native.ts
    +++ b/src/libs/Sound/index.native.ts
    @@ -6,9 +6,8 @@ import type {AudioSource} from 'expo-audio';
     import type {ValueOf} from 'type-fest';
     
    -import {createAudioPlayer, setAudioModeAsync} from 'expo-audio';
    -
     import {getIsMuted, SOUNDS, withMinimalExecutionTime} from './BaseSound';
    +import Log from '@libs/Log';
     
     // Sound assets are statically imported for bundling.
     const SOUND_ASSETS = {
    @@ -21,11 +20,20 @@ const SOUND_ASSETS = {
     // - playsInSilentMode: false — respect the device's silent/mute switch (iOS)
     // - shouldPlayInBackground: false — push notification sounds are played by the system
     // - interruptionMode: 'mixWithOthers' — don't interrupt other audio (e.g. music)
    -const audioModeConfigured = setAudioModeAsync({playsInSilentMode: false, shouldPlayInBackground: false, interruptionMode: 'mixWithOthers'});
    +let audioModePromise: Promise<void> | null = null;
    +const ensureAudioModeConfigured = () => {
    +    if (!audioModePromise) {
    +        audioModePromise = (async () => {
    +            try {
    +                const {setAudioModeAsync} = await import('expo-audio');
    +                await setAudioModeAsync({playsInSilentMode: false, shouldPlayInBackground: false, interruptionMode: 'mixWithOthers'});
    +            } catch (error) {
    +                Log.warn('[Sound] Failed to configure audio mode:', error);
    +            }
    +        })();
    +    }
    +    return audioModePromise;
    +};
     
     const playSound = async (soundFile: ValueOf<typeof SOUNDS>) => {
         if (getIsMuted()) {
             return;
         }
     
         const source = SOUND_ASSETS[soundFile];
         if (!source) {
             return;
         }
     
    -    // Wait for audio mode to be configured before playing to ensure the session
    -    // uses the .ambient category (which won't interrupt music or other audio)
    -    await audioModeConfigured;
    -
    -    const player = createAudioPlayer(source);
    +    try {
    +        await ensureAudioModeConfigured();
    +        const {createAudioPlayer} = await import('expo-audio');
    +        const player = createAudioPlayer(source);
    +
    +        const subscription = player.addListener('playbackStatusUpdate', (status) => {
    +            if (!status.didJustFinish) {
    +                return;
    +            }
    +
    +            subscription.remove();
    +            player.remove();
    +        });
    +
    +        player.play();
    +    } catch (error) {
    +        Log.warn('[Sound] Failed to play sound:', error);
    +    }
     };

    What automated tests can you add to prevent this from re-occurring?

    Add a test in tests/unit/SoundTest.ts verifying that:

    1. Importing @libs/Sound does not trigger any native calls or throw even when native audio modules are unavailable.
    2. Invoking playSound safely handles failure without crashing when native modules reject.
  12. 22 remaining items

  13. melvin-bot commented on Oct 31, 2026

    @melvin-bot

    Payment Summary

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  14. changed the title [-][Due for payment 2026-10-31] [$175] [Sentry: APP-MD4] HybridApp Android: startup abort, "Cannot find native module 'ExpoAudio'"[/-] [+][Due for payment 2026-11-04] [$175] [Sentry: APP-MD4] HybridApp Android: startup abort, "Cannot find native module 'ExpoAudio'"[/+] on Nov 3, 2026
  15. mallenexpensify commented on Nov 3, 2026

    @mallenexpensify
    Contributor

    Paying in two days

  16. ikevin127 commented on Nov 6, 2026

    @ikevin127
  17. mallenexpensify commented on Nov 7, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @ikevin127 due $175 via NewDot
    Contributor+: @daledah due $175 via NewDot

  18. quinthar commented on Nov 8, 2026

    @quinthar
    Contributor

    Approved $175 to @ikevin127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions