I’ve been able to successfully compile our native plugin and test it on device and everything works beautifully. I’ve also compiled our native plugin for the simulator and it works there as well. Each plugin is a static library file.
The only issue is that if I import both native plugin files into Unity. There’s no way for me to tell Unity to use one for device and one for simulator. I am able to select the CPU type, but both the simulator and device are ARM64 in this case.
Hi there! As you say, unfortunately there’s no option in the plugin importer to differentiate between target SDK. However, you can create a build preprocessor script to do this. This is what we’ve done in the com.unity.xr.visionos plugin, and you can look at com.unity.xr.visionos/Editor/VisionOSBuildProcessor.PreProcessor.cs for an example of how this is done. In short, you use SetIncludeInBuildDelegate on the PluginImporter for the two plugins, and in that callback you can check against the current sdkVersion to decide which one should be included/excluded. In our case, we put Device or Simulator in the path, but you could use guids or whatever criteria you’d like to decide.
Here’s the relevant code from our build preprocessor (missing some context, but I think it should get the idea across):
static void SetRuntimePluginCopyDelegate()
{
var allPlugins = PluginImporter.GetAllImporters();
foreach (var plugin in allPlugins)
{
if (!plugin.isNativePlugin)
continue;
// Process pre-compiled library separately. Exactly one version should always be included in the build
// regardless of whether the loader is enabled. Otherwise, builds will fail in the linker stage
if (plugin.assetPath.Contains(k_PreCompiledLibraryName))
{
plugin.SetIncludeInBuildDelegate(ShouldIncludePreCompiledLibraryInBuild);
continue;
}
}
}
static bool ShouldIncludePreCompiledLibraryInBuild(string path)
{
// Exclude libraries that don't match the target SDK
if (PlayerSettings.VisionOS.sdkVersion == VisionOSSdkVersion.Device)
{
if (path.Contains("Simulator"))
return false;
}
else
{
if (path.Contains("Device"))
return false;
}
return true;
}