Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Native audio plugin bundle Import Settings for iOS build

Discussion in 'Audio & Video' started by aihodge, Apr 1, 2015.

  1. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    I've created a custom native audio plugin using the UnityNativeAudioPluginSDK project as a reference, created the .bundle in Xcode, and dropped it into my game project's Plugins folder. My custom plugin works as expected when I play my game in the Unity Editor, however when I build to iOS I receive this warning in Xcode:

    I suspect that this is due to inappropriately configured Import Settings on the plugin bundle. Unity's page documenting native audio plugins states:

    Is anyone aware of documentation of the specific steps required to do this static linkage? Or the iOS-specific Import Settings required to get my plugin working on my iOS devices? Thanks!
     
  2. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    You need to build your plugin as a static lib (.a file ) first. Then, after building you're unity project, in XCode link the library you've built( link binary with libraries panel, I think ).
     
  3. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    Thanks gregzo - I can build the static library, but is the static library meant to be added alongside the .bundle in the Unity project, but in Plugins > iOS? I've tried building the project this way Xcode gives the same warning. It seems I am still missing a step...should I be using DllImport to register the plugin with Unity (the docs refer adding the plugin registration explicitly to the startup code of the app)?
     
    Last edited: Apr 2, 2015
  4. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi,

    Just had another look at the example project, and nope, no iOS example.

    I can't try this myself right now, but here's what you can do:

    - Don't add your .a to your unity project
    - Build, not build and run
    - in Xcode, select your target, build phases, Link Binary with Libraries, drag and drop your .a in there
    - Try clean and build
    - If that fails, maybe try registering your effect manually, in main.mm, just like it's done in the demo project's PluginList.h

    Not sure it'll help, I'll try myself as soon as I have time.
     
  5. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    Hey @gregzo, were you able to try this out on your device? I've been looking into how plugin rendering devices are added to Unity's startup code and it appears to take place in -(void)preStartUnity{} in UnityAppController.mm but I haven't been able to find an actual code example.

    Are there any Unity dev staff out there that are willing to guide us?
     
    Last edited: Apr 8, 2015
  6. hugettini

    hugettini

    Joined:
    Apr 1, 2013
    Posts:
    19
    I've got the same issue with Android.
    • I've build the static "libnative.so" lib for armeabi.
    • Added the lib to the Plugins folder /Asset/Plugins/Android/libnative.so
    • Marked for android on the inspector.
    • Used the UnityNativeAudioPluginSDK scene and script

    Any help would be great :p
     
  7. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Time's a bit scarce these days, haven't had the time to give it a shot yet...
     
  8. hugettini

    hugettini

    Joined:
    Apr 1, 2013
    Posts:
    19
    Finally I managed to compile and run.
    The problem was compiling the android so.

    Here is my Android.mk if someone need it (the LOCAL_MODULE is the important part)

    include $(CLEAR_VARS)

    # override strip command to strip all symbols from output library; no need to ship with those..
    # cmd-strip = $(TOOLCHAIN_PREFIX)strip $1


    LOCAL_ARM_MODE := arm
    LOCAL_PATH := $(NDK_PROJECT_PATH)
    LOCAL_MODULE := AudioPluginDemo
    LOCAL_CFLAGS := -Werror
    LOCAL_C_INCLUDES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
    FILE_LIST := $(wildcard $(LOCAL_PATH)/audio/*.cpp)
    LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
    LOCAL_LDLIBS := -llog

    include $(BUILD_SHARED_LIBRARY)
     
  9. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    That's awesome @hugettini, thanks for sharing. I recently got native audio plugins working on iOS as well. Here are the steps that I took, after building the audio plugin as a static library (.a):
    1. Add your static library and its associated header into Plugins > iOS
    2. Add AudioPluginInterface.h to Plugins > iOS
    3. Build your Xcode project from Unity
    4. In UnityAppController.h, import "AudioPluginInterface.h"
    5. In UnityAppController.mm, add the following line to preStartUnity{}:
    Code (CSharp):
    1. UnityRegisterAudioPlugin(&UnityGetAudioEffectDefinitions);
     
    Last edited: May 1, 2015
    CharlesVerron and ovirta like this.
  10. djnewty

    djnewty

    Joined:
    Apr 7, 2015
    Posts:
    40
    Hi aihodge,

    Is there any chance you can clarify which header file you used for the associated header added to Plugins > iOS?

    I cant seem to get the AudioPluginDemo.a static library working. Everything seems to be working ok. Xcode has built the static library and I used the resulting "AudioPluginDemo.a" to build in unity. However, I get no sound/functionality from the plugins. For instance in the "303 and 909 like synths" example, all I get is a voice sample - whereas on windows there are other samples (a 303 and a 909).

    Just wondering how you built the AudioPluginDemo ? There is no static project with included. I just edited the .xcodeproj package to be a static library instead of a bundle - you think this might be the problem?

    Apart from this I'm at a loss at what it could be. There are no errors, but the Native Audio Plugins are definitely not working :/

    Cheers
     
    Last edited: Dec 9, 2015
  11. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    I meant to say the header file (.h) that Xcode generates when you create a new static library target, which should share the same name as the newly created static library. I don't think you can get away with just renaming the .bundle as a .a static library (if I understand you correctly and that's in fact what you have done).
     
  12. ovirta

    ovirta

    Joined:
    Mar 20, 2015
    Posts:
    42
    Thanks @aihodge for sharing these steps. Following those (and plenty of trial and error) I was able to get my custom audio static library running on iOS. I was struggling with xcode complaining about plugin being build for wrong archtecture among other things. Not sure whether really necessary but after stripping the static library (.a) to support only arm64 it was correctly being loaded when running the app on iPad.

    Lipo-command on Mac was helpful pointing out the needed library architecture btw if anyone else is struggling with this ("lipo -info staticlibrary.a")
     
    aihodge likes this.
  13. GladGrif

    GladGrif

    Joined:
    Mar 1, 2017
    Posts:
    1
    Thanks for the good advice aihodge! I realize that it has been a while since this post, but thought I'd give it a shot anyway ...

    I am able to create a custom .bundle in Xcode, and can run the spatializer demo scene in the editor and as a stand-alone application on my Mac. I am also able to create a static library (.a-file) in Xcode and building for iOS seems to go well in Unity. Also using the resulting Xcode project to install the app on my iPhone seems to go well, but I get the following error when runninng it on the phone:

    Audio source failed to initialize audio spatializer. An audio spatializer is specified in the audio project settings, but the associated plugin was not found or initialized properly. Please make sure that the selected spatializer is compatible with the target.

    So, what I would like to ask is if whether the steps you describe really are all that are needed ...? Is it perhaps necessary to define the extern methods in a C# file as follows:

    [DllImport ("__Internal")]
    private static extern float FooPluginFunction();

    as described in the Unity documentation ? https://docs.unity3d.com/Manual/PluginsForIOS.html

    Any help would be greatly appreciated. :)
     
  14. k552

    k552

    Joined:
    Mar 30, 2017
    Posts:
    1
    @hugettini

    Any chance of a little help with compiling using NDK? I am trying to get a pipeline going using the demo plugins from the unity native audio sdk.

    I have my .so files generated by ndk-build (using your Android.mk), but running on Android gives me a complete crash. Where there any other steps you had to go through?
     
  15. jcctt

    jcctt

    Joined:
    May 4, 2017
    Posts:
    2
    Hello,
    I realise this is an old thread, but I'm hoping I can get some advice.
    Trying to build the example project from the SDK for iOS without success.
    If I try to build the project generated from Unity (that already contains the static library) in Xcode, i get:
    Audio effect Demo RingModulator could not be found. Check that the project contains the correct native audio plugin libraries and that the importer settings are set up correctly.​

    When importing AudioPluginInterface.h and adding "UnityRegisterAudioPlugin(&UnityGetAudioEffectDefinitions);" to the preStartUnity method I get this Mach-O linker error:
    Undefined symbols for architecture armv7:
    "_UnityGetAudioEffectDefinitions", referenced from:
    -[UnityAppController preStartUnity] in UnityAppController.o​
    Is there an example of what the settings should be for building the static library in Xcode somewhere?
    Or an example of building a simple app for iOS that uses the example projects in the SDK?
    Any help woud be greatly appreciated.
     
    toneTechnican likes this.
  16. toneTechnican

    toneTechnican

    Joined:
    Oct 22, 2019
    Posts:
    5
    Hey aihodge,

    Can you confirm if this works in the latest build of Unity? Have been running into some errors with Metal. More info can be found here --> https://forum.unity.com/threads/native-audio-plugin-bundle-does-not-work-on-ios.788210/
     
  17. manassehclifford

    manassehclifford

    Joined:
    Sep 20, 2021
    Posts:
    8
    Hi where can i find more information on how to write the plugins for android ios and other platforms, i managed to build native audio plugins for mac and windows using the juce library (it has a good audio api and a wrapper for building plugins), i presume i can make some changes to the wrapper ang get things going , but i am unsure where to start
     
  18. manassehclifford

    manassehclifford

    Joined:
    Sep 20, 2021
    Posts:
    8
    A little update but still looking for help. I built an .apk file from my jucer project and the .apk files that i built , when unzipped contained the .so files t. I imported them into my unity project as described and on debugging i get the same error as mentioned above. I am unable to find and android.mk file in my build project. so i am very confused