Skip to content

Building from Source

Gindemit Konstantin edited this page May 12, 2023 · 7 revisions

Building from Source

Building on Windows for the Windows Operating System (x64-Debug, x64-Release, x86-Debug, x86-Release):

To build the plugin on Windows most conveniently, follow these steps:

  1. Open the project in Visual Studio (ensure the CMake addon is installed).
  2. Run the 'build all' command.
  3. The CMakeLists.txt file is located in the "unity-vorbis/projects/CMake/" directory.
  4. Depending on the configuration selected in Visual Studio, the VorbisPlugin.dll will be found in "unity-vorbis/projects/CMake/out/build/[selected_configuration]".
  5. For instance, if the selected configuration is x64-Debug, then the VorbisPlugin.dll will be stored in the "unity-vorbis/projects/CMake/out/build/x64-Debug" folder.

Building on Windows for the Android Operating System:

Here's how you can build the project for Android:

  1. Open the project in Android Studio (it's in the "unity-vorbis/projects/Android/" directory).
  2. Ensure that both the Android SDK and Android NDK are installed.
  3. To build for multiple ABIs, add them to the build.gradle file as follows: abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'.
  4. Run the 'Build->Make Project' menu item.
  5. In case of a fatal error: 'ogg/ogg.h' file not found, this can be circumvented by copying the ogg.h and os_types.h files from the directory "unity-vorbis\dependency\ogg\include\ogg" to "unity-vorbis\projects\Android\app.cxx\cmake\debug[TARGET_ABI]\ogg_build\include\ogg".
  6. If a linker error stating that vorbis_encode_init_vbr could not be resolved appears, open the "unity-vorbis\dependency\vorbis\lib\CMakeLists.txt" file and comment out the if(WIN32) and endif() lines. The code should look like this:
#if(WIN32)
    list(APPEND VORBIS_SOURCES vorbisenc.c)
#endif()
  1. For some reason, the vorbis plugin developers only include the vorbisenc.c file for Windows. The code above will include this file in the Vorbis library.
  2. By default, you'll get the debug versions of the libraries. To build the release versions, you need to run the Gradle task "compileReleaseSources". To do this, click the Gradle menu on the top right side of Android Studio and navigate to "Android->app->Tasks->build->compileReleaseSources".
  3. The output libraries can be found in the following directories: unity-vorbis\projects\Android\app\build\intermediates\cmake\[debug OR release]\obj\[TARGET ABI]\.

Building for MacOS on Mac OSX Operating System:

This section guides you through the process of building a plugin for MacOS on Mac OSX operating system using CMake.

First, ensure that CMake is installed on your system. If you're unsure, you can check if CMake is already installed by typing cmake in the terminal. If it's not installed, use the following command to install it:

brew install cmake

Once CMake is installed, navigate to the "unity-vorbis/projects/CMake" directory. From this directory, you can generate the xCode project using the following command:

cmake -S . -B ./buildOSX -G Xcode -DVORBIS_OSX=1

With the project now set up, you can build it directly from the terminal. Use the following command to build the project:

cmake --build ./buildOSX --config Release

Once the build process is successful, you will find the static libraries for iOS in the VorbisPluginBuild folder.

Building for the iOS Operating System on MacOS:

To create a build for iOS, it's necessary to initialize the iOS Toolchain submodule found in the dependency folder. CMake must also be installed.

Follow these steps to complete the process:

  1. Verify the Installation of CMake: Open your terminal and type "cmake". If CMake is not installed, the terminal will not recognize the command. In this case, install it by running the following command:
brew install cmake
  1. Navigate to the CMake Directory: Once CMake is installed, go to the unity-vorbis/projects/CMake directory.

  2. Generate an xCode Project: Run the following command to generate an xCode project:

cmake -S . -B ./buildIOS -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../dependency/cmake-ios-toolchain/ios.toolchain.cmake -DPLATFORM=OS64 -DVORBIS_IOS=1
  1. Build the Project: You can build the project from the terminal using the following command:
cmake --build ./buildIOS --config Release --target VorbisPlugin

Alternatively, you can open the xCode project located in the buildIOS directory. Within xCode, select VorbisPlugin->Any iOS Device (arm64) and build it.

  1. Locating the Static Libraries: After a successful build, you can find the static libraries for iOS in the VorbisPluginBuild folder. Open this directory in Finder and copy the libraries to your Unity project.

Please note that these libraries are built with the arm64 architecture only (compatible with iPhone 6 and newer). If you need to build for armv7, you must select standard libraries under 'Build Settings Architectures' for the VorbisPlugin build target within xCode.

By default, the build process will create Debug libraries. If you need Release libraries, modify the current scheme in xCode by navigating to Product->Scheme->Edit Scheme and changing the build configuration.