You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to build for iOS 18, I got a number of undefined symbols:
After looking through it and online for some help, I found that in the file LofeltHaptics.cs it imports all the symbols that are undefined:
// imports of iOS Framework bindings[DllImport("__Internal")]privatestaticexternboollofeltHapticsDeviceMeetsMinimumRequirementsBinding();[DllImport("__Internal")]privatestaticexternIntPtrlofeltHapticsInitBinding();[DllImport("__Internal")]privatestaticexternboollofeltHapticsLoadBinding(IntPtrcontroller,[In]byte[]bytes,longsize);[DllImport("__Internal")]privatestaticexternboollofeltHapticsPlayBinding(IntPtrcontroller);[DllImport("__Internal")]privatestaticexternboollofeltHapticsStopBinding(IntPtrcontroller);[DllImport("__Internal")]privatestaticexternboollofeltHapticsSeekBinding(IntPtrcontroller,floattime);[DllImport("__Internal")]privatestaticexternboollofeltHapticsSetAmplitudeMultiplicationBinding(IntPtrcontroller,floatfactor);[DllImport("__Internal")]privatestaticexternboollofeltHapticsSetFrequencyShiftBinding(IntPtrcontroller,floatshift);[DllImport("__Internal")]privatestaticexternboollofeltHapticsLoopBinding(IntPtrcontroller,boolenable);[DllImport("__Internal")]privatestaticexternfloatlofeltHapticsGetClipDurationBinding(IntPtrcontroller);[DllImport("__Internal")]privatestaticexternboollofeltHapticsReleaseBinding(IntPtrcontroller);[DllImport("__Internal")]privatestaticexternboollofeltHapticsSystemHapticsTriggerBinding(inttype);[DllImport("__Internal")]privatestaticexternboollofeltHapticsSystemHapticsInitializeBinding();[DllImport("__Internal")]privatestaticexternboollofeltHapticsSystemHapticsReleaseBinding();
After looking online and following this, it turned out there are no iOS binaries in the project, only Android, macOS and Windows:
Temporary fix:
Removed all references to iOS in the file, as I don't use that library for now. It built successfully afterwards:
// Copyright (c) Meta Platforms, Inc. and affiliates. usingUnityEngine;usingSystem;
#if (UNITY_ANDROID&&!UNITY_EDITOR)usingSystem.Text;usingSystem.Runtime.InteropServices;
#endif
namespaceLofelt.NiceVibrations{/// <summary>/// C# wrapper for the Lofelt Studio Android SDK./// </summary>////// You should not use this class directly, use HapticController instead, or the/// <c>MonoBehaviour</c> classes HapticReceiver and HapticSource.////// The Lofelt Studio Android SDK is included in Nice Vibrations as pre-compiled/// binary plugins.////// Each method here delegates to the Android SDK. The methods should only be/// called if DeviceMeetsMinimumPlatformRequirements() returns true, otherwise there will/// be runtime errors.////// All the methods do nothing when running in the Unity editor.////// Before calling any other method, Initialize() needs to be called.////// Errors are printed and swallowed, no exceptions are thrown on Android in this class.publicstaticclassLofeltHaptics{
#if (UNITY_ANDROID&&!UNITY_EDITOR)staticAndroidJavaObjectlofeltHaptics;staticAndroidJavaObjecthapticPatterns;staticlongnativeController;// Cache the most commonly used JNI method IDs during initialization.// Calling a Java method via its method ID is faster and uses less allocations than// calling a method by string, like e.g. 'lofeltHaptics.Call("play")'.staticIntPtrplayMethodId=IntPtr.Zero;staticIntPtrstopMethodId=IntPtr.Zero;staticIntPtrseekMethodId=IntPtr.Zero;staticIntPtrloopMethodId=IntPtr.Zero;staticIntPtrsetAmplitudeMultiplicationMethodId=IntPtr.Zero;staticIntPtrplayMaximumAmplitudePattern=IntPtr.Zero;[DllImport("lofelt_sdk")]privatestaticexternboollofeltHapticsLoadDirect(IntPtrcontroller,[In]byte[]bytes,longsize);
#endif
/// <summary>/// Initializes the Android library plugin./// </summary>////// This needs to be called before calling any other method.publicstaticvoidInitialize(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)try{using(varunityPlayerClass=newAndroidJavaClass("com.unity3d.player.UnityPlayer"))using(varcontext=unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity")){lofeltHaptics=newAndroidJavaObject("com.lofelt.haptics.LofeltHaptics",context);nativeController=lofeltHaptics.Call<long>("getControllerHandle");hapticPatterns=newAndroidJavaObject("com.lofelt.haptics.HapticPatterns",context);playMethodId=AndroidJNIHelper.GetMethodID(lofeltHaptics.GetRawClass(),"play","()V",false);stopMethodId=AndroidJNIHelper.GetMethodID(lofeltHaptics.GetRawClass(),"stop","()V",false);seekMethodId=AndroidJNIHelper.GetMethodID(lofeltHaptics.GetRawClass(),"seek","(F)V",false);loopMethodId=AndroidJNIHelper.GetMethodID(lofeltHaptics.GetRawClass(),"loop","(Z)V",false);setAmplitudeMultiplicationMethodId=AndroidJNIHelper.GetMethodID(lofeltHaptics.GetRawClass(),"setAmplitudeMultiplication","(F)V",false);playMaximumAmplitudePattern=AndroidJNIHelper.GetMethodID(hapticPatterns.GetRawClass(),"playMaximumAmplitudePattern","([F)V",false);}}catch(Exceptionex){Debug.LogException(ex);}
#endif
}/// <summary>/// Releases the resources used by the Android library plugin./// </summary>publicstaticvoidRelease(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)try{lofeltHaptics.Dispose();lofeltHaptics=null;hapticPatterns.Dispose();hapticPatterns=null;}catch(Exceptionex){Debug.LogWarning(ex);}
#endif
}publicstaticboolDeviceMeetsMinimumPlatformRequirements(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)returnJNIHelpers.Call<bool>(lofeltHaptics,"deviceMeetsMinimumRequirements");
#else
returntrue;
#endif
}publicstaticvoidLoad(byte[]data){
#if (UNITY_ANDROID&&!UNITY_EDITOR)// For performance reasons, we do *not* call into the Java API with// `lofeltHaptics.Call("load", data)` here. Instead, we bypass the Java layer and// call into the native library directly, saving the costly conversion from// C#'s byte[] to Java's byte[].//// No exception handling needed here, lofeltHapticsLoadDirect() is a native method that// doesn't throw an exception and instead logs the error.lofeltHapticsLoadDirect((IntPtr)nativeController,data,data.Length);
#endif
}publicstaticfloatGetClipDuration(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)returnJNIHelpers.Call<float>(lofeltHaptics,"getClipDuration");
#else
//No haptic clip was loaded with Lofelt SDK, so it returns 0.0freturn0.0f;
#endif
}publicstaticvoidPlay(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)JNIHelpers.Call(lofeltHaptics,playMethodId);
#endif
}publicstaticvoidPlayMaximumAmplitudePattern(float[]timings){
#if (UNITY_ANDROID&&!UNITY_EDITOR)JNIHelpers.Call(hapticPatterns,playMaximumAmplitudePattern,timings);
#endif
}publicstaticvoidStop(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)JNIHelpers.Call(lofeltHaptics,stopMethodId);
#endif
}publicstaticvoidStopPattern(){
#if (UNITY_ANDROID&&!UNITY_EDITOR)try{hapticPatterns.Call("stopPattern");}catch(Exceptionex){Debug.LogWarning(ex);}
#endif
}publicstaticvoidSeek(floattime){
#if (UNITY_ANDROID&&!UNITY_EDITOR)JNIHelpers.Call(lofeltHaptics,seekMethodId,time);
#endif
}publicstaticvoidSetAmplitudeMultiplication(floatfactor){
#if (UNITY_ANDROID&&!UNITY_EDITOR)JNIHelpers.Call(lofeltHaptics,setAmplitudeMultiplicationMethodId,factor);
#endif
}publicstaticvoidSetFrequencyShift(floatshift){// Removed for iOS}publicstaticvoidLoop(boolenabled){
#if (UNITY_ANDROID&&!UNITY_EDITOR)JNIHelpers.Call(lofeltHaptics,loopMethodId,enabled);
#endif
}publicstaticvoidTriggerPresetHaptics(inttype){// Removed for iOS}}}
The text was updated successfully, but these errors were encountered:
When trying to build for iOS 18, I got a number of undefined symbols:
After looking through it and online for some help, I found that in the file
LofeltHaptics.cs
it imports all the symbols that are undefined:After looking online and following this, it turned out there are no iOS binaries in the project, only Android, macOS and Windows:
Temporary fix:
Removed all references to iOS in the file, as I don't use that library for now. It built successfully afterwards:
The text was updated successfully, but these errors were encountered: