Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compile Unity Android plugins #22

Open
BrianTopp opened this issue May 9, 2023 · 4 comments
Open

Unable to compile Unity Android plugins #22

BrianTopp opened this issue May 9, 2023 · 4 comments
Assignees

Comments

@BrianTopp
Copy link

Hello,

I submitted this through the Cycling 74 support, and they asked me to also post this here.

I’m struggling to get RNBO plugins to properly compile for Unity Android. I’ve been able to compile for Mac and PC (on respective platforms) but am unable to compile the same patches for Unity Android. I’ve been following along with the github docs but keep running into the same issue where it appears as though all of the files are created properly in the initial step, but then when building I get a number of errors that appear to be related to the RNBOWrapper.cpp. I’ve included the output errors below, which hopefully you can make sense of. I also fully understand that this repo is still in an experimental stage, so mainly want to draw attention to the issues and see if there is a current solution, or if perhaps there was some issue with my approach.

Thanks!

steps : Following the build steps on the RNBO Unity Audio Plugin repo, specifically for Android building

notes : This is console output, including the commands I inputted to start the build process:

PS E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build> cmake .. -DANDROID_ABI=arm64-v8a -DCMAKE_TOOLCHAIN_FILE="C:\Program Files\Unity\Hub\Editor\2022.2.0f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\build\cmake\android.toolchain.cmake" -DPLUGIN_NAME="MyChorus" -DANDROID_PLATFORM=29 -DPLUGIN_UNITY_PLATFORM_NAME=Android
-- Building for: Visual Studio 17 2022
-- Android: Targeting API '29' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
-- Android: Selected unified Clang toolchain
-- The CXX compiler identification is unknown
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Unity/Hub/Editor/2022.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- building for Android with bit depth 64 for CPU ARM64
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done (3.2s)
-- Generating done (0.0s)
-- Build files have been written to: E:/Repos/RNBO Unity Plugins/RNBO Build SRC/build
PS E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build> cmake --build .
MSBuild version 17.5.0+6f08c67f3 for .NET Framework

ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
ANDROID_SDK_ROOT=C:\Program Files (x86)\Android\android-sdk
ANT_HOME=
JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
NDK_ROOT=C:\Microsoft\AndroidNDK\android-ndk-r23c
Checking Build System
ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
ANDROID_SDK_ROOT=C:\Program Files (x86)\Android\android-sdk
ANT_HOME=
JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
NDK_ROOT=C:\Microsoft\AndroidNDK\android-ndk-r23c
Building Custom Rule E:/Repos/RNBO Unity Plugins/RNBO Build SRC/CMakeLists.txt
RNBOWrapper.cpp
In file included from :380:
(1,9): warning : 'ANDROID_API' macro redefined [-Wmacro-redefined] [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
#define ANDROID_API 29
^
(370,9): note: previous definition is here
#define ANDROID_API ANDROID_MIN_SDK_VERSION
^
In file included from E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp:7:
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\export\rnbo\src\3rdparty\readerwriterqueue/readerwriterqueue.h(93,6): error : cannot use 'throw' with exceptions disabled [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\R
NBOUnityPlugin.vcxproj]
throw std::bad_alloc();
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\export\rnbo\src\3rdparty\readerwriterqueue/readerwriterqueue.h(108,5): error : cannot use 'throw' with exceptions disabled [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build
RNBOUnityPlugin.vcxproj]
throw std::bad_alloc();
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(22,23): error : no type named 'shared_mutex' in namespace 'std'; did you mean 'timed_mutex'? [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityP
lugin.vcxproj]
using rw_mutex = std::shared_mutex;

timed_mutex
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\mutex(235,24): note: 'timed_mutex' declared here
class _LIBCPP_TYPE_VIS timed_mutex
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(23,42): error : no template named 'shared_mutex' in namespace 'std'; did you mean 'shared_ptr'? [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUni
tyPlugin.vcxproj]
using write_lock = std::unique_lock<std::shared_mutex>;
~~~~~^~~~~~~~~~~~
shared_ptr
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\memory(3698,28): note: 'shared_ptr' declared here
class _LIBCPP_TEMPLATE_VIS shared_ptr
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(23,42): error : use of class template 'std::shared_ptr' requires template arguments [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcx
proj]
using write_lock = std::unique_lock<std::shared_mutex>;
^
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\memory(3698,28): note: template is declared here
class _LIBCPP_TEMPLATE_VIS shared_ptr
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(24,24): error : no template named 'shared_lock' in namespace 'std' [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
using read_lock = std::shared_lock<std::shared_mutex>;
~~~~~^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(24,41): error : no template named 'shared_mutex' in namespace 'std'; did you mean 'shared_ptr'? [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUni
tyPlugin.vcxproj]
using read_lock = std::shared_lock<std::shared_mutex>;
~~~~~^~~~~~~~~~~~
shared_ptr
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\memory(3698,28): note: 'shared_ptr' declared here
class _LIBCPP_TEMPLATE_VIS shared_ptr
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(246,33): error : copying variable of type 'std::atomic<Callback *>' invokes deleted constructor [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUni
tyPlugin.vcxproj]
static std::atomic<Callback *> globalTransportCallback = nullptr;
^ ~~~~~~~
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\atomic(1774,7): note: copy constructor of 'atomic<(anonymous namespace)::Callback *>' is implicitly deleted because base class '__atomic
_base<(anonymous namespace)::Callback *>' has a deleted copy constructor
: public __atomic_base<_Tp*>
^
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\atomic(1649,5): note: '__atomic_base' has been explicitly marked deleted here
__atomic_base(const __atomic_base&) = delete;
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(254,49): error : copying member subobject of type 'std::atomic<Callback *>' invokes deleted constructor [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build
\RNBOUnityPlugin.vcxproj]
std::atomic<Callback *> mTransportCallback = nullptr;
^~~~~~~
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\atomic(1774,7): note: copy constructor of 'atomic<(anonymous namespace)::Callback *>' is implicitly deleted because base class '__atomic
_base<(anonymous namespace)::Callback *>' has a deleted copy constructor
: public __atomic_base<_Tp*>
^
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\atomic(1649,5): note: '__atomic_base' has been explicitly marked deleted here
__atomic_base(const __atomic_base&) = delete;
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(373,5): error : unknown type name 'write_lock' [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
write_lock wlock(instances_mutex);
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(409,4): error : unknown type name 'write_lock' [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
write_lock wlock(instances_mutex);
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(508,3): error : use of undeclared identifier 'read_lock'; did you mean 'realloc'? [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxpr
oj]
read_lock rlock(RNBOUnity::instances_mutex);
^~~~~~~~~
realloc
C:\\Microsoft\AndroidNDK\android-ndk-r23c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\malloc.h(61,7): note: 'realloc' declared here
void* realloc(void* __ptr, size_t __byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(508,12): error : expected ';' after expression [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
read_lock rlock(RNBOUnity::instances_mutex);
^
;
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(508,3): warning : expression result unused [-Wunused-value] [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
read_lock rlock(RNBOUnity::instances_mutex);
^~~~~~~~~
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(508,13): error : use of undeclared identifier 'rlock' [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
read_lock rlock(RNBOUnity::instances_mutex);
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(525,2): error : unknown type name 'write_lock' [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
write_lock wlock(RNBOUnity::instances_mutex);
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(549,2): error : unknown type name 'write_lock' [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
write_lock wlock(RNBOUnity::instances_mutex);
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(581,7): error : use of class template 'std::lock_guard' requires template arguments [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcx
proj]
std::lock_guard guard(localmutex);
^
C:\\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include\__mutex_base(80,1): note: template is declared here
lock_guard
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(587,3): error : cannot use 'try' with exceptions disabled [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
try {
^
E:\Repos\RNBO Unity Plugins\RNBO Build SRC\src\RNBOWrapper.cpp(625,4): error : cannot use 'try' with exceptions disabled [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
try {
^
CLANGCOMPILE : fatal error : too many errors emitted, stopping now [-ferror-limit=] [E:\Repos\RNBO Unity Plugins\RNBO Build SRC\build\RNBOUnityPlugin.vcxproj]
2 warnings and 20 errors generated.

system : Windows 10, Dell G5 Desktop, MaxMSP 8.5.4

expected : Should produce an arm64 android plugin for Unity
actual : Several errors are thrown in relation to eh RNBOWrapper.cpp (included below)
@x37v x37v self-assigned this May 10, 2023
@x37v
Copy link
Contributor

x37v commented May 10, 2023

I'm going to look into this further but it looks like Visual Studio was getting in the way on my end.. I switched the generator to "Unix Makefiles" and built successfully

C:\Users\xnor\dev\rnbo.unity.audioplugin\build>cmake .. -DANDROID_PLATFORM=29 -DANDROID_ABI=arm64-v8a -DCMAKE_TOOLCHAIN_FILE="C:\Program Files\Unity\Hub\Editor\2021.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\build\cmake/android.toolchain.cmake" -DRNBO_EXPORT_DIR="Z:\Documents\export\sync-cycle" -DRNBO_CPP_DIR="Z:\Documents\export\sync-cycle\rnbo" -DPLUGIN_NAME="Sync Cycle" -G"Unix Makefiles"
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Unity/Hub/Editor/2021.3.16f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- building for Android with bit depth 64 for CPU ARM64
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/xnor/dev/rnbo.unity.audioplugin/build

C:\Users\xnor\dev\rnbo.unity.audioplugin\build>cmake --build .
[ 20%] Building CXX object CMakeFiles/RNBOUnityPlugin.dir/src/RNBOWrapper.cpp.o
[ 40%] Building CXX object CMakeFiles/RNBOUnityPlugin.dir/src/AudioPluginUtil.cpp.o
[ 60%] Building CXX object CMakeFiles/RNBOUnityPlugin.dir/Z_/Documents/export/sync-cycle/rnbo_source.cpp.o
[ 80%] Building CXX object CMakeFiles/RNBOUnityPlugin.dir/Z_/Documents/export/sync-cycle/rnbo/RNBO.cpp.o
[100%] Linking CXX shared module SyncCycle/Assets/Plugins/Android/arm64-v8a/libSyncCycle.so
[100%] Built target RNBOUnityPlugin

@x37v
Copy link
Contributor

x37v commented May 10, 2023

for future reference: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android

and the examples for calling cmake on the commandline for NDK builds on windows use Ninja
https://developer.android.com/studio/projects/configure-cmake#call-cmake-cli

@x37v
Copy link
Contributor

x37v commented May 10, 2023

@BrianTopp interesting, I added some notes RE my experience with building for Android on windows: https://github.com/Cycling74/rnbo.unity.audioplugin#notes-for-cross-compiling-for-android-on-windows

I am also running VS 2022 and I don't see those same issues RE the locks. Here is my commandline for reference:

C:\Users\xnor\dev\rnbo.unity.audioplugin\build-vs>cmake .. -DANDROID_PLATFORM=29 -DANDROID_ABI=arm64-v8a -DCMAKE_TOOLCHAIN_FILE="C:\Program Files\Unity\Hub\Editor\2021.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\build\cmake/android.toolchain.cmake" -DRNBO_EXPORT_DIR="Z:\Documents\export\sync-cycle" -DRNBO_CPP_DIR="Z:\Documents\export\sync-cycle\rnbo" -DPLUGIN_NAME="Sync Cycle" -DANDROID_CPP_FEATURES=exceptions
-- Building for: Visual Studio 17 2022
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Unity/Hub/Editor/2021.3.16f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- building for Android with bit depth 64 for CPU ARM64
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/xnor/dev/rnbo.unity.audioplugin/build-vs

C:\Users\xnor\dev\rnbo.unity.audioplugin\build-vs>cmake --build .
MSBuild version 17.5.0+6f08c67f3 for .NET Framework

  ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
  ANDROID_SDK_ROOT=C:\Program Files (x86)\Android\android-sdk
  ANT_HOME=
  JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
  NDK_ROOT=C:\\Microsoft\AndroidNDK\android-ndk-r23c
  Checking Build System
  ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
  ANDROID_SDK_ROOT=C:\Program Files (x86)\Android\android-sdk
  ANT_HOME=
  JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
  NDK_ROOT=C:\\Microsoft\AndroidNDK\android-ndk-r23c
  Building Custom Rule C:/Users/xnor/dev/rnbo.unity.audioplugin/CMakeLists.txt
  RNBOUnityPlugin.vcxproj -> C:\Users\xnor\dev\rnbo.unity.audioplugin\build-vs\SyncCycle\Assets\Plugins\Android\arm64-v8a\libSyncCycle.so
  ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
  ANDROID_SDK_ROOT=C:\Program Files (x86)\Android\android-sdk
  ANT_HOME=
  JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
  NDK_ROOT=C:\\Microsoft\AndroidNDK\android-ndk-r23c
  Building Custom Rule C:/Users/xnor/dev/rnbo.unity.audioplugin/CMakeLists.txt

@BrianTopp
Copy link
Author

Thanks! Yeah, after your previous comments I switched to using Ninja, and that seems to have solved all build issues on my end. I'm not sure what the issue with VS 2022 was. It looks like the only difference in what you've just posted is the "-DANDROID_CPP_FEATURES=exceptions", but I've tried recompiling with that argument and am still getting the same lock errors. I'll continue to use Ninja as that works well. Thanks for your help!

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

No branches or pull requests

2 participants