Unity-Technologies / NativeAudioPlugins

MIT License
135 stars 28 forks source link

Cannot export UnityGetAudioEffectDefinitions symbol when set fvisibility=hidden #6

Closed Mikeye666 closed 8 months ago

Mikeye666 commented 2 years ago

Problem: We are shipping commercial audio plugin and we would like to hide symbols of internal components. However, the UNITY_AUDIODSP_EXPORT_API macro does not force visibility so we ended up hiding UnityGetAudioEffectDefinitions symbol as well, resulting in Unity can't find our audio plugin on android.

To reproduce:

  1. Download AudioPluginInterface.h
  2. Make some simple audio plugin (maybe a gain knob?)
  3. Using Cmake, compile it as a android .so with following flags: -fvisibility=hidden -fvisibility-inlines-hidden
  4. In Unity, build an Android game using your audio plugin, and install it on your android device
  5. Open up Android logcat on PC/Mac, and record out-comming log
  6. Run your game on Android device, you should experience that the audio plugin you made didn't do anything
  7. Stop Android Logcat, search for your plugin name in the recorded log, you should be able to find errors saying your plugin could not be found.

Proposed fix: Inside AudioPluginInterface.h, change

if PLATFORM_WIN

define UNITY_AUDIODSP_EXPORT_API __declspec(dllexport)

else

define UNITY_AUDIODSP_EXPORT_API

endif

to this:

if PLATFORM_WIN

define UNITY_AUDIODSP_EXPORT_API __declspec(dllexport)

else

define UNITY_AUDIODSP_EXPORT_API attribute((visibility("default")))

endif

Hope this got fixed soon.

cliffordmanasseh commented 2 years ago

Hey Man I am facing a lot of trouble with the android implementation as well, ive exported my plugins succesfully to .so using android.mk and have tried the same with Cmake as well. in both cases i always get a plugin not found error while debugging the app. I tried the fix mentioned above. didnt workout either.

Mikeye666 commented 2 years ago

Hey Man I am facing a lot of trouble with the android implementation as well, ive exported my plugins succesfully to .so using android.mk and have tried the same with Cmake as well. in both cases i always get a plugin not found error while debugging the app. I tried the fix mentioned above. didnt workout either.

Sound like one (or multiple) of the following is wrong:

  1. UnityGetAudioEffectDefinitions symbol is not exported for your android .so

A quick way to check if your symbol get correctly exported by your .so build: On Mac/Linux:

nm -gD .so | grep 'UnityGetAudioEffectDefinitions'

On Windows, use dumpbin and findstr instead.

  1. Your plugin dll is not loaded for your app deployed ABI What ABI did your plugin code used to build, armv7 or armv8? Whichever you used, you should make sure you .so libraries gets loaded for android runtime and correct ABI

  2. Your unity build uses an Android ABI that doesn't have an .so that contains your plugin. You can see the ABI used for your Unity build in player settings -> others. If you are building with armv7 only, and you don't have an armv7 .so for your plugin, Unity won't find your plugin.

I would not classify myself as Unity expert, but hope those helps :)