Search code examples
javamacosaudioinstall4jmicrophone

Java application not recording from microphone when packaged using install4j


I have a Java application that uses the Java sound API to record sound from the systems microphone. When run on macOS from the terminal, sound recording works as expected, but no sound is recorded when the app is packaged using install4j.

I am using Liberica JDK 17 as the runtime.

In Install4J, I use an entitlements file like this.

<?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>com.apple.security.device.audio-input</key>
    <true/>
    <key>com.apple.security.device.microphone</key>
    <true/>
  </dict>
</plist>

When run from Terminal using java -jar, the app requests microphone access. When packaged and run via Install4, there is no request for a permission.

The app is properly signed / notarized with a certificate.

Any ideas what I might be missing?

Thanks!


Solution

  • I finally figured this out. The Info.plist file needs an entry like this, explaining why the app needs access to the microphone:

    <key>NSMicrophoneUsageDescription</key>
    <string>This app requires access to the microphone for recording audio.</string>
    

    You can specify this in install4j in the "Launchers" section, open the relevant launcher and its settings, and under "macOS options" use "customize plist file" to add the lines above.