使用Xamarin集成ARCore遇问题,示例项目无法正常构建
Hey there, I’ve been down this exact rabbit hole with Xamarin and ARCore—totally get how frustrating it is when sample projects don’t work as expected! Let’s break down your issues and fix them step by step:
1. The Outdated ARCore.Xamarin Project
That repo hasn’t been updated in years, and both Xamarin.Android and ARCore have gone through massive API breaking changes since then. Updating all NuGet packages blindly will almost certainly cause build failures because the code is written for older versions of both tools.
Here’s what you can try if you still want to use this project as a reference:
- Don’t update all packages at once. Check the project’s original
TargetFrameworkVersionin the.csprojfile, then only update the ARCore binding package to a version compatible with that Xamarin.Android version. - Alternatively, take the core logic (like plane detection, object placement) and rewrite it to fit the latest ARCore API—this is more work but will be future-proof.
2. Xamarin’s Official ARCore HelloAR Sample Build Failures
The official Xamarin ARCore component should be up-to-date, so the problem is likely with your environment or project configuration. Let’s check the most common culprits:
- Missing ARCore SDK: Make sure you’ve installed the Google ARCore SDK via the Android SDK Manager (not just the NuGet package). The SDK version should match the version of
Xamarin.Google.ARCoreyou’re using. - Incompatible Target Android Version: ARCore requires at least Android 10 (API 29) as the target framework. Double-check your project’s properties to confirm this is set correctly.
- NuGet Restore Issues: Visual Studio sometimes fails to restore packages properly. Try right-clicking the solution → Restore NuGet Packages, or delete the
objandbinfolders manually then rebuild the solution. - Missing Permissions/Manifest Config: Ensure your
AndroidManifest.xmlincludes these critical entries:<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera.ar" android:required="true" /> <meta-data android:name="com.google.ar.core" android:value="required" /> - Check Build Errors: Always look at the specific error messages! If it’s a missing class, you might have mismatched package versions; if it’s a permission error, the manifest is the issue.
A Better Alternative: Build from Scratch
If you’re stuck on the samples, consider starting fresh with a minimal setup:
- Create a new Xamarin.Android blank project.
- Install the
Xamarin.Google.ARCoreNuGet package. - Add an
ArFragmentto your layout (or create a custom fragment that inherits from it). - In your main activity, initialize the AR session, handle frame updates, and add logic for placing virtual objects.
- Double-check the manifest permissions and meta-data mentioned above.
This approach avoids the baggage of old sample code and lets you learn the current API directly.
内容的提问来源于stack exchange,提问作者Justin

