76

When I start Android Emulator, the audio on my Mac desktop stops. It starts again when I close the emulator.

Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65

6 Answers6

172

I found easier way than accepted answer from @Ivo Stoyanov to solve this. Just open the emulator config file (for my mac it's /Users/{myname}/.android/avd/{emulator_name}/config.ini and set

hw.audioInput=no
hw.audioOutput=no

Screen from visual studio code

If it's not working then you should "Wipe Data" and "Cold Boot Now" in Android Virtual Device Manager screen from android virtual device manager

Paweł Kanarek
  • 2,317
  • 2
  • 10
  • 17
  • Not a bad one, but with this solution you have to edit the config for every emulator that you create. – Ivo Stoyanov Jul 16 '21 at 14:24
  • 3
    Yeah, just wanted to share :) Also with that i can control which emulator can use audio and which not. And creating new emulators is rather not so frequent activity – Paweł Kanarek Jul 16 '21 at 15:51
  • I believe this is the best solution because setting no audio permanently for all emulator will cause further problems when we have to test audio. So, if you are working with audio, just create two emulators- with and without audio output. Use the one which supports your needs while development. – Chetan Goyal Feb 19 '22 at 21:31
  • 7
    Be sure you're editing the correct `.ini` file. It should be the `config.ini`, NOT `.ini` – muya_ Aug 04 '22 at 04:24
  • For me I had to set audioOutput to `yes` – אורי orihpt Nov 14 '22 at 18:08
64

When the emulator is started with enabled audio, sometimes it overrides the audio channel of the Mac machine. This happens even if you disable access to the microphone for Android studio in Security settings. To fix the issue you should start the emulator with disabled audio.

There are two options to start the emulator with disabled audio:

I. Start the emulator from the console:

emulator -avd Pixel_2_API_27 -qemu -no-audio

II. If you want to start the emulator with disabled audio directly from Android studio, you should replace the emulator file with a script that will run emulator with additional parameters:

Android Studio by default uses the binary $ANDROID_SDK/emulator/emulatorwhich is located in: ~/Library/Android/sdk/emulator/

You have to do the following:

  1. Rename the emulator binary to emulator-original.

  2. Create a bash script text file with the name emulator that contains:

#!/bin/bash    
~/Library/Android/sdk/emulator/emulator-original $@ -qemu -no-audio
  1. Set the newly created script permissions with chmod +x emulator

Now, Android Studio will run your script that will run the original binary with the addtitional parameters to disable emulator's audio.

N.B. Kudos for the script solution to MartinCR who proposed it here.

Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65
  • This is a better solution: https://stackoverflow.com/a/64696876/1942551 – karlingen Dec 23 '21 at 09:07
  • https://stackoverflow.com/a/64696876/1942551 does not work on Mac OS. You cannot set 'studio.emu.params' permanently. – Ivo Stoyanov Dec 23 '21 at 09:57
  • I get the error "Intel HAXM is required to run this AVD. No emulator installed" when performing the steps above. Any suggestions? – Sunkas Feb 09 '22 at 14:47
  • For the first option the -qemu flag actually seems unnecessary, including -no-audio without -qemu works for me – konnovdev May 15 '22 at 13:19
19

To build off @paweł-kanarek answer, here's a small script that loops through all of the Android emulators on your machine and adds

hw.audioInput = no
hw.audioOutput = no

at the end of the file (or replaces it if you already have these options specified).

#!/bin/bash
find ~/.android/avd -name "config.ini" | while read line
do
   awk '!/audio/' $line > tmp
   rm $line
   mv tmp $line
   echo "hw.audioInput = no" >> $line 
   echo "hw.audioOutput = no" >> $line 
done

To run this, simply add this code to a local bash script (I named mine 'disable_emulator_sound.sh'). Then, make it executable with the command chmod +x disable_emulator_sound.sh and run it with ./disable_emulator_sound.sh.

Note: as mentioned in the original answer, after making this change, if it's not working you might have to go into the emulator options menu and run 'Wipe Data' and then run 'Cold Boot Now'.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Praxder
  • 2,315
  • 4
  • 32
  • 51
9

Based on Joachim's post:

If you have some Bluetooth headphones and notice a strange hissing sounds while the emulator is running, you might find it useful to add the -noaudio

To have a permanent fix to affect all your virtual devices do the following:

Create a .plist file e.g. studio-environments.plist in the folder ~/Library/LaunchAgents/ with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>setenv.studio.emu.params</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/launchctl</string>
        <string>setenv</string>
        <string>studio.emu.params</string>
        <string>-writable-system,-noaudio</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

To load these changes directly (e.g. to apply changes without rebooting your Mac)

launchctl load ~/Library/LaunchAgents/studio-environments.plist

Extras:

If you run the command while it is already loaded, you will get an error message like this

Load failed: 5: Input/output error

You have to unload it before with

launchctl unload ~/Library/LaunchAgents/studio-environments.plist

You can check your changes with this command:

launchctl getenv studio.emu.params

Note: You won’t hear any sound from the emulator anymore, but the hissing will be gone too

Morteza Rastgoo
  • 6,772
  • 7
  • 40
  • 61
  • 1
    Good answer. But it would help if your plist above had `-writable-system,-noaudio` as the environment variable value. – humblehacker Feb 03 '22 at 04:41
5

You can also withdraw the microphone access for Android Studio in MacOS System Settings in "Security & Privacy". (Though I don't know how well/if it works, since I went for the config.ini approach.)

Step by Step: Link to a better explaination with pictures

  • Go to MacOS "System Preferences" > "Security & Privacy" > Microphone.
  • Click on lock icon on the bottom left to enable editing.
  • Then uncheck the checkmark on Android Studio in the application list on the right.

Kudos to Matt McKenna who shared this on his blog. He wrote about the solution and the background here: https://blog.mmckenna.me/android-emulators-vs-bluetooth-headphones

sebokopter
  • 326
  • 5
  • 15
-1

on Mac OS Ventura: System preferences > Privacy and Security > Microphone > un-check Android Studio

Benoit Jadinon
  • 1,082
  • 11
  • 21