Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find UnityARCore when doing React Native Android build using Unity project

I have a simple React Native app that is based on https://github.com/azesmway/react-native-unity

I use the <UnityView> component from this package to load my exported Unity project

If I download a simple Unity project - e.g. https://github.com/IVainqueur/flop-unity and then do an Android export then I can put the build into my unity/builds/android/unityLibrary directory. I then do an app build and I can successfully see the Unity project

However, if I want to use a more advanced Unity project such as the AR Foundation samples from https://github.com/Unity-Technologies/arfoundation-samples then I have a problem. I can do an Android export from Unity, put the files into the unity/builds/android/unityLibrary directory and then do an Android build of my React Native app

The React Native app build fails with the errors below. There seems to be a step missing that allows the React Native app to read the libs directory.

FAILURE: Build failed with an exception.

What went wrong:
Could not determine the dependencies of task ':unityLibrary:compileDebugAidl'.
Could not resolve all task dependencies for configuration ':unityLibrary:debugCompileClasspath'.
Could not find :arcore_client:.
Required by:
project :unityLibrary
Could not find :UnityARCore:.
Required by:
project :unityLibrary
Could not find :ARPresto:.
Required by:
project :unityLibrary
Could not find :unityandroidpermissions:.
Required by:
project :unityLibrary

My build.gradle file contains:

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 22
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
        
    }
    repositories {
        google()
        mavenCentral()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }

}

My settings.gradle file contains:

rootProject.name = 'projectName'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
include ':unityLibrary'
project(':unityLibrary').projectDir=new File('../unity/builds/android/unityLibrary')
include ':unityLibrary:xrmanifest.androidlib'

The file structure I have is:

like image 952
Chris Avatar asked Apr 07 '26 09:04

Chris


1 Answers

You need to import :arcore_client, UnityARCore, ARPresto and unityandroidpermissions into your project the same way you include unity library.

Your settings.gradle file should look something like this:

rootProject.name = 'projectName'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
include ':unityLibrary'
project(':unityLibrary').projectDir=new File('../unity/builds/android/unityLibrary')
include ':unityLibrary:xrmanifest.androidlib'

include ':arcore_client'
project(':arcore_client').projectDir=new File('../unity/builds/android/arcore_client')

include ':UnityARCore'
project(':UnityARCore').projectDir=new File('../unity/builds/android/UnityARCore')

include ':ARPresto'
project(':ARPresto').projectDir=new File('../unity/builds/android/ARPresto')

include ':unityandroidpermissions'
project(':unityandroidpermissions').projectDir=new File('../unity/builds/android/unityandroidpermissions')

May also need to add:

 implementation(name: 'arcore_client', ext:'aar')
    implementation(name: 'UnityARCore', ext:'aar')
    implementation(name: 'ARPresto', ext:'aar')
  
    implementation(name: 'unityandroidpermissions', ext:'aar')

to build.gradle file dependencies.

May not be exactly that but should get you started. You may need to install addition .aar files that are in your unity folder.

like image 80
Overture Avatar answered Apr 08 '26 22:04

Overture



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!