Skip to content

Fix #1698: use OpenSL ES to reimplement libjsound.so, fix javax.sound audio on Android - #1700

Draft
razureink wants to merge 18 commits into
FCL-Team:mainfrom
razureink:fix-issue-1698-jsound-alsa
Draft

Fix #1698: use OpenSL ES to reimplement libjsound.so, fix javax.sound audio on Android#1700
razureink wants to merge 18 commits into
FCL-Team:mainfrom
razureink:fix-issue-1698-jsound-alsa

Conversation

@razureink

@razureink razureink commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

之前方案是在 alsa_stub 里集成 OpenSL ES 做音频输出,但会和 jsound 冲突,而且 CI 也编不过去。

现在把 alsa_stub 改回纯桩实现,不干实际音频的事,只保证 libjsound.so 链接不报错。音频输出由新增的 libjsound.so 来处理,它直接走 OpenSL ES,不需要 ALSA。

改动:

  • alsa_stub/alsa_stub.c 恢复成简单 ALSA 桩,所有接口返回 -19(无设备),不链接 OpenSL ES
  • jsound/jsound.c 用 OpenSL ES 重新实现了 javax.sound 的 DirectAudioDevice 和 PortMixer 原生接口,支持 PCM 播放和音量控制
  • CMakeLists.txt 加了 jsound 目标,链接 OpenSLES;alsa_stub 也保留 OpenSLES 链接(CI 要求)
  • FCLauncher.java 启动时把 libjsound.so 复制到 JRE 的 lib 目录下,因为 Java 25 的模块系统不走 java.library.path,只认自己的目录

…droid

libjsound.so in JDK 25+ Android builds now links against libasound.so.2
(ALSA), which is not available on Android. This causes javax.sound
operations to fail with UnsatisfiedLinkError.

Changes:
- Add minimal ALSA stub library (alsa_stub.c) that provides all the
  symbols libjsound.so needs, built with SONAME libasound.so.2
- Register ALSA stub in CMakeLists.txt so it gets compiled for all
  Android architectures and bundled in the APK
- Update setUpJavaRuntime() in FCLauncher.java to load the ALSA stub
  before loading JDK libraries, ensuring libjsound.so can resolve its
  ALSA dependency
- Skip libjsound.so in locateLibs() since it will be loaded lazily
  by the JVM when javax.sound is used, at which point the ALSA stub
  is already available
android
)

# 仅在arm64-v8a架构下链接EGL和GLESv2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来这里把很多的注释都删了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已恢复,请刷新查看

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi

@razureink
razureink marked this pull request as draft July 24, 2026 06:29
@razureink
razureink requested a review from aaaapai July 24, 2026 06:29
@razureink
razureink force-pushed the fix-issue-1698-jsound-alsa branch from 1138d7a to 69d38f7 Compare July 24, 2026 14:06
@razureink
razureink force-pushed the fix-issue-1698-jsound-alsa branch from 5ae4ff6 to 386ba8e Compare July 24, 2026 14:46
@razureink razureink changed the title Fix #1698: Add ALSA stub for libjsound.so compatibility on Android Fix #1698: ? OpenSL ES ???? libjsound.so,?? Android ? javax.sound ?????? Jul 24, 2026
@razureink razureink changed the title Fix #1698: ? OpenSL ES ???? libjsound.so,?? Android ? javax.sound ?????? Fix #1698: 用 OpenSL ES 重新实现 libjsound.so,解决 Android 上 javax.sound 没声音的问题 Jul 24, 2026
@razureink razureink changed the title Fix #1698: 用 OpenSL ES 重新实现 libjsound.so,解决 Android 上 javax.sound 没声音的问题 Fix #1698: use OpenSL ES to reimplement libjsound.so, fix javax.sound audio on Android Jul 24, 2026
@razureink
razureink force-pushed the fix-issue-1698-jsound-alsa branch from d9ece1c to e50fe70 Compare July 27, 2026 00:02
@razureink
razureink force-pushed the fix-issue-1698-jsound-alsa branch from e50fe70 to 81502dc Compare July 27, 2026 01:23
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.

3 participants