In this quickstart guide, we will be integrating the ARwayKit SDK with Android Kotlin. This example will be using Unity as a Library to integrate into an Android app.
Installed Versions
In this guide, we will be using the following versions:
Android Studio: 2022.1.1
Unity: 2022.3.29f1 LST
Android Min API Level 24
Download the ARwayKit SDK
Steps
Download the ARwayKit SDK project from GitHub as a ZIP. You can contact us for access to the ARwayKit SDK.
Create a Basic Project in Android Studio
Create a new sample Android Project, for this example a new project using the Empty Activity template will be used with the language set to Kotlin and the minimum SDK set to API 24.
Generate the Gradle Project for the Android Platform
Make sure to add the Account ID and Secret Key variables to the Unity project. Follow the guide for Building from the Source Code for instructions.
The package name in the Unity Editor will need to match the package name of the Kotlin app.
Build Steps
In Unity select File -> Build Settings.
Switch the Platform to Android.
Select option "Export Project".
Export the ARwayKit Unity SDK to a new folder and name it "androidBuild" and place it in the base directory for the Android Kotlin project.
Add the Unity Android Build to the Android App
Steps
Open the Android sample app in Android Studio.
Open the settings.gradle file and make the following changes to the code as shown below. Ensure that the line 'androidBuild\\unityLibrary' matches the path to the ARwayKit Unity SDK export.
You will be notified that changes have been made to the grade files, click the 'Sync Now' button to continue.
If everything succeeds you should be able to see the unityLibrary module added in the Android view.
Preparing the Sample Project
To run the ARwayKit Unity SDK on Android, we need to integrate Unity as a library in our Android project. This will allow us to use the Unity engine within our app and run Unity scenes alongside native Android activities. In this section, we will go through the steps to set up Unity as a library and add the ARwayKit Unity SDK to the project.
For this we will be creating a new blank Activity in the project called MainUnityActiviy. Make sure the generate the layout file as well.
In the above file, the addControlsToUnityFrame() method sets the positions of the buttons added to the layout. These buttons are not required but showcase the methods to unload the Unity player.
To pass data to Unity, you can call the following method:
Next, find the newly created layout file under src/main/res/layout called activity_main_unity.xml. This adds the buttons to open the Unity activity and close the app.
Once you have completed all the necessary steps to integrate the ARwayKit Unity SDK into your Android Kotlin project, you are ready to build, run, and debug your app. If everything has been properly configured, you should be able to run the app seamlessly with the ARwayKit Unity SDK.
Unity will run in another process android:process=":Unity" (AndroidManifest.xml at app module).
Additional information about integrating Unity as a library into a standard Android app can be found in the following links: