Wasted-Audio / hvcc

The heavy hvcc compiler for Pure Data patches. Updated to python3 and additional generators
https://wasted-audio.github.io/hvcc/
GNU General Public License v3.0
260 stars 30 forks source link

Building for Unity Android doesn't compile a plugin #53

Closed maxcelar closed 2 years ago

maxcelar commented 2 years ago

Thanks for sharing this great work. I'm trying to compile a plugin with the unity generator for Android arm64 architecture (to be used on Oculus Quest 2).

I get no errors but there are no errors as shown below:

Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16.
Android NDK: WARNING:C:/Users/Max/Desktop/to-test/noise/unity/android/jni/Android.mk:heavy_lib: non-system libraries in linker flags: -latomic
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK:     current module
Android NDK: WARNING:C:/Users/Max/Desktop/to-test/noise/unity/android/jni/Android.mk:heavy_plugin: non-system libraries in linker flags: -latomic
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK:     current module
[arm64-v8a] Compile        : hv_static <= HvControlBinop.c
[arm64-v8a] Compile        : hv_static <= HvControlCast.c
[arm64-v8a] Compile        : hv_static <= HvControlDelay.c
[arm64-v8a] Compile        : hv_static <= HvControlRandom.c
[arm64-v8a] Compile        : hv_static <= HvControlSlice.c
[arm64-v8a] Compile        : hv_static <= HvControlSystem.c
[arm64-v8a] Compile        : hv_static <= HvControlUnop.c
[arm64-v8a] Compile        : hv_static <= HvControlVar.c
[arm64-v8a] Compile        : hv_static <= HvLightPipe.c
[arm64-v8a] Compile        : hv_static <= HvMessage.c
[arm64-v8a] Compile        : hv_static <= HvMessagePool.c
[arm64-v8a] Compile        : hv_static <= HvMessageQueue.c
[arm64-v8a] Compile        : hv_static <= HvSignalBiquad.c
[arm64-v8a] Compile        : hv_static <= HvSignalVar.c
[arm64-v8a] Compile        : hv_static <= HvTable.c[arm64-v8a][arm64-v8a] Compile++      : hv_static <= Heavy_noise.cpp Compile++      :[arm64-v8a][arm64-v8a]
[arm64-v8a]
 hv_static <= HvHeavy.cpp Compile++      : heavy_plugin <= AudioPluginUtil.cpp[arm64-v8a] Compile++      : heavy_plugin <= Hv_noise_AudioPlugin.cpp

 Compile        : hv_static <= HvUtils.c
 Compile++      : hv_static <= HeavyContext.cpp

[arm64-v8a] StaticLibrary  : libhv_static.a
[arm64-v8a] SharedLibrary  : libHv_heavy_AudioLib.so
[arm64-v8a] SharedLibrary  : AudioPlugin_Hv_heavy.so
[arm64-v8a] Install        : libHv_heavy_AudioLib.so => libs/arm64-v8a/libHv_heavy_AudioLib.so
[arm64-v8a] Install        : AudioPlugin_Hv_heavy.so => libs/arm64-v8a/AudioPlugin_Hv_heavy.so

The process with the last line is shown here and no builds appear in the unity/build/ dir.

Android.mk:


LOCAL_PATH := $(call my-dir)

# ------------------------------------------------------------------------------
# static heavy library
include $(CLEAR_VARS)
LOCAL_MODULE := hv_static
# LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NEON -O3 -ffast-math -fPIC
LOCAL_CPPFLAGS := -std=c++11
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../source/heavy
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/../../source/heavy/*.c)
LOCAL_SRC_FILES += $(wildcard $(LOCAL_PATH)/../../source/heavy/*.cpp)
# LOCAL_ARM_NEON := true
# LOCAL_ARM_MODE := arm
include $(BUILD_STATIC_LIBRARY)

# ------------------------------------------------------------------------------
# audiolib.so
include $(CLEAR_VARS)
LOCAL_MODULE := heavy_lib
LOCAL_MODULE_FILENAME := libHv_heavy_AudioLib
# LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NEON -O3 -ffast-math -fPIC
LOCAL_CPPFLAGS := -std=c++11
# there are no additional source files for the library wrapper,
# just build a shared library version of it
LOCAL_WHOLE_STATIC_LIBRARIES := hv_static
LOCAL_LDLIBS := -latomic
# LOCAL_ARM_NEON := true
# LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)
ifeq ($(TARGET_ARCH),arm)
LOCAL_ARM_NEON := true
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NEON -O3 -ffast-math -fPIC
endif
ifeq ($(TARGET_ARCH),x86_64)
LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NONE -O3 -ffast-math -fPIC
endif

# ------------------------------------------------------------------------------
# libplugin.so
include $(CLEAR_VARS)
LOCAL_MODULE := heavy_plugin
LOCAL_MODULE_FILENAME := AudioPlugin_Hv_heavy
# LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NEON -O3 -ffast-math -fPIC
LOCAL_CPPFLAGS := -std=c++11
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../source
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/../../source/unity/*.c)
LOCAL_SRC_FILES += $(wildcard $(LOCAL_PATH)/../../source/unity/*.cpp)
LOCAL_LDLIBS := -latomic
LOCAL_STATIC_LIBRARIES := hv_static
# LOCAL_ARM_NEON := true
# LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)
ifeq ($(TARGET_ARCH),arm)
LOCAL_ARM_NEON := true
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NEON -O3 -ffast-math -fPIC
endif
ifeq ($(TARGET_ARCH),x86_64)
LOCAL_CFLAGS := -std=c11 -DNDEBUG -DHV_SIMD_NONE -O3 -ffast-math -fPIC
endif

Application.mk:

APP_OPTIM := release
APP_STL := c++_static
APP_ABI := arm64-v8a
APP_MODULES := heavy_lib heavy_plugin

Do you have any ideas about what could be going wrong? Thanks in advance

Also when using hvcc command before compiling the plugin, I get this error:

PS C:\Users\Max\Desktop\to-test\noise> hvcc whitenoise.pd -n noise -g unity
  1) ←[91mError←[0m c2unity: Unicode-objects must be encoded before hashing

I'm not sure if that's a problem or how to resolve it? It still proceeds with generating and compiling for Windows x64 platform works.

Thanks!

maxcelar commented 2 years ago

Resolved with help on Discord.

The plugins are compiled to unity\android\libs\ instead of unity\build\android as written in the documentation.

You will need to generate the cs script separately using the vs2015 compiler.

Also if you are naming your plugins using the -n parameter you will need to rename the android plugins to Hv_{PATCH_NAME}_AudioLib and AudioPlugin_Hv_{PATCH_NAME}.

Make sure to choose the right CPU architecture in the Plugin Inspector.

Tested on Quest 2.