gradle 使用Unity项目进行React Native Android构建时无法找到UnityARCore

nlejzf6q  于 5个月前  发布在  React
关注(0)|答案(1)|浏览(92)

我有一个基于https://github.com/azesmway/react-native-unity的简单React Native应用程序
我使用此包中的<UnityView>组件加载导出的Unity项目
如果我下载一个简单的Unity项目-例如https://github.com/IVainqueur/flop-unity,然后进行Android导出,那么我可以将构建版本放入unity/builds/android/unityLibrary目录。然后我进行应用构建,我可以成功地看到Unity项目
然而,如果我想使用更高级的Unity项目,例如来自https://github.com/Unity-Technologies/arfoundation-samples的AR Foundation示例,那么我就有问题了。我可以从Unity进行Android导出,将文件放入unity/builds/android/unityLibrary目录,然后对我的React Native应用进行Android构建
React Native应用构建失败,出现以下错误。似乎缺少一个步骤,允许React Native应用读取libs目录。

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

字符串
我的build.gradle文件包含:

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")
    }

}


我的settings.gradle文件包含:

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'


我的文件结构是:
x1c 0d1x的数据

clj7thdc

clj7thdc1#

你需要导入:arcore_client,UnityARCore,ARPresto和unityandroid权限到你的项目中,就像你包含unity库一样。
您的settings.gradle文件应该看起来像这样:

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')

字符串
可能还需要添加:

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


构建.gradle文件依赖项。
可能不完全是这样,但应该让你开始。你可能需要安装额外的.aar文件,在你的团结文件夹。

相关问题