Day 2 : Create a single AR App for Android & iOS using Unity and AR Foundation


In this tutorial, we’ll take the previous project we used to create an ARKit specific app and we will show you how to add ARCore support to it, making it a universal cross-platform AR Application.

This is part of a 30 day sprint where we try to publish 30 projects in 30 days, this means building full projects from scratch. Double checking the code, writing the tutorial and then posting it . If there are any typos do let us know and I hope you enjoy this tutorial and project.

Introduction

In a previous tutorial, we learned to build an AR app for iOS using Unity and AR Foundation which leveraged ARKit. Although we did touch upon AR Foundation in this post, we’ll take a deeper dive into its working and understanding to build a universal AR Application. This app will work on both Android and iOS.

Generally, to build an AR Experience for Android, ARCore is used which is developed and maintained by Google. ARCore does have native integration with Unity and can be developed-for independently if that’s the use case. On the other hand, we have ARKit which is for developing AR applications on iOS. The ARKit SDK is maintained by Unity themselves.

Moreover, both ARCore and ARKit have a set of common core features that work in more or less a similar way albeit with a different engine running them. Wouldn’t it be easier to build a single app that uses these common core features without having to write code for both platforms simultaneously?

This is where AR Foundation comes in. Although ARCore does work on iOS, it still uses ARKit underneath and isn’t all that elegant implementation wise. It provides an abstracted API for the core functionality of both ARKit and ARCore, which can be used to create cross-platform scenes and scripts as well. Based on the target platform and runtime, AR Foundation will switch to the appropriate SDK as required.


What if I want a specific functionality that only ARKit provides?

Let’s take example –  environmental probes are still available and can be used using the ARKit SDK.

Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close

Getting Started

The AR Foundation is available using the UnityEngine.XR namespace. It consists of a number of sub-systems that are responsible for a specific platform-independent feature. The XRPlaneSubsystem under AR Subsystems is what will be used for Plane Detection as we saw in the ARKit tutorial. If we wanted to write up some custom behavior using scripts that is what we would use.


These sub-systems are then supported by a Provider that provides the platform-specific implementation. In our case, the providers will be the ARKit plugin and the ARCore plugin.


Also, note that these plugins are also wrappers against a native implementation for that platform. The wrappers expose the native API to Unity through C#.

Modifications

Following the linked tutorial.

Let’s first import ARCore related dependencies.

Once we have the project open let’s go to Package Manager by going to Window -> Package Manager and searching for “arcore”


Select the ARCore XR Plugin from the list and click on install. Unity will then download the package and import it into our project. This might take a minute or two.

Now that we have all of our providers, we can now change our target platform to Android.

Go to -> File -> Build Settings -> select Android and click on Switch Platform

That’s it!

It’s as simple as that to maintain a single project for both Android and iOS. To make the development easier or in case you are planning to use Git (which you should), we can split the project into two parts.


Everything inside the /Assets can be a single repository that becomes platform independent which is all of our art, scenes, and scripts.

The root-project folder becomes a separate repository which is our platform-dependent one. Since unity stores all the project settings under the Project Settings folder, we can then maintain two different repositories for our Android and iOS apps that contain the root project but ignores everything inside the Assets folder & a second platform-independent repository which contains the actual application project itself.


Finally, by setting up our project structure in this way, we make taking builds for both Android and iOS much faster and scalable, especially for bigger projects.

Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close

One response to “Day 2 : Create a single AR App for Android & iOS using Unity and AR Foundation”

  1. […] I’m using an iPhone and will be running unity on a Mac, but since we’re using ARFoundation it will also work on Android as well. Also, I have written a post on how to do just that, you can follow that here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Join 30 AR projects in 30 days and become a better AR developer
GET FREE LESSONS

Learn AR projects & source code

We shall send you an email with the link to the best starter lesson in 5 minutes
Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close
Download source code for this project & get updates of future projects
Download Source Code

Download Source Code

Close