You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Firebase推送通知时出现AudioFlinger内存不足等错误

Hey there, let's figure out this AudioFlinger memory issue you're facing when using Firebase push notifications. That error code -12 is a clear sign of insufficient system memory for the audio track system, and it's popping up alongside your push notification triggers. Let's break down how to troubleshoot and fix this step by step:

排查与解决Firebase推送关联的AudioFlinger内存错误(status -12)

First, let's clarify: Error code -12 maps to Android's ENOMEM (out of memory) status. The AudioFlinger service can't allocate enough memory to create an audio track/record, and this is happening when Firebase push notifications fire—likely because the push is triggering audio-related logic in your app, or it's the final trigger that pushes a memory-strapped system over the edge.

1. Audit your notification's audio settings

If you're using a custom notification sound with Firebase:

  • Avoid oversized audio files (stick to under 500KB if possible) and use optimized formats like MP3 or AAC with moderate bitrates.
  • Check for repeated audio resource initialization—don't create a new Ringtone instance every time a push comes in without releasing it.

Here's a quick code fix example:

// ❌ Bad: Creates a new Ringtone every time, no cleanup
Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(customSoundUri));
ringtone.play();

// ✅ Better: Reuse the instance and clean up when done
private static Ringtone sNotificationRingtone;
public void playNotificationSound(Context context, Uri soundUri) {
    if (sNotificationRingtone == null) {
        sNotificationRingtone = RingtoneManager.getRingtone(context, soundUri);
    }
    if (sNotificationRingtone.isPlaying()) {
        sNotificationRingtone.stop();
    }
    sNotificationRingtone.play();
}

2. Check your app's audio recording/playback logic

If your app handles Firebase pushes by launching audio-related features (like recording or playback):

  • Make sure all AudioRecord, MediaPlayer, or similar instances are immediately released with release() after use—memory leaks here can eat up system audio resources over time.
  • Avoid overlapping audio sessions: If a push triggers audio, ensure no other audio processes are running in the background that could compete for memory.

3. Optimize for low-memory devices

Low-RAM devices are far more prone to this error. Tweak your push handling logic to reduce memory strain:

  • Avoid heavy operations (like large file downloads or bulk data parsing) directly in the Firebase push callback. Offload these to a background thread with a delay instead.
  • Use Android Studio's Profile tool to hunt for memory leaks in your app—unreleased objects can slowly drain system resources until the audio service crashes.
  • Optionally, disable non-essential audio prompts on low-memory devices:
    val notificationBuilder = NotificationCompat.Builder(context, CHANNEL_ID)
        .setContentTitle(title)
        .setContentText(content)
    
    // Skip custom sound on low-RAM devices
    val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
    if (!activityManager.isLowRamDevice) {
        notificationBuilder.setSound(customSoundUri)
    }
    

4. Update your Firebase SDK

Old versions of Firebase Messaging might have compatibility issues with Android's audio service. Make sure you're using the latest stable SDK:

// Update to the latest version (check Firebase docs for current numbers)
implementation 'com.google.firebase:firebase-messaging:23.4.0'

5. Test to narrow down the root cause

  • Reproduce the issue on a low-memory device to see if the error correlates directly with push notifications.
  • Temporarily disable notification sounds entirely—if the error disappears, you know the audio configuration is the problem.

Quick note: The log line createRecordTrack_l() initCheck failed -12 mentions an audio recording track failing. If you aren't explicitly using audio recording in your app, check if any third-party libraries (including Firebase extensions) are quietly launching recording sessions in the background. Use Android Studio's App Inspection to monitor active audio sessions.

内容的提问来源于stack exchange,提问作者Bashar Syr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:17:37