我正在尝试将 Unity 作为库集成到我正在做的项目的本机 Android 项目中。它将使用 Unity 应用程序在增强现实中呈现本机 Android 应用程序中的项目。
为此,我遵循[github.com/Unity-Technologies/uaal-example](https://github.com/Unity-Technologies/uaal-example/blob/b41579464b50edf6682a154f3cbb9e098aa5ba3d/docs/android.md#integrating -unity-as-a-library-into-standard-android-app)开始使用。
但是,尽管按照上述步骤操作,我仍无法将 unityLibrary 正确添加到我的本机 Android 应用程序中。即使“unityLibrary”模块出现在我的项目树中,如下所示,
它不包括应有的相应资产、资源和类,
尝试构建项目时出现的错误如下。
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not resolve project :unityLibrary.
Required by:
project :app
> No matching configuration of project :unityLibrary was found. The consumer was configured to find a component for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.0.2' but:
- None of the consumable configurations have attributes.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
我对 Unity 开发和编程本身还是新手,目前不知道我在这里做错了什么。我按照以下步骤操作,通过构建设置和项目设置设置 Unity 项目,通过导出生成 Gradle 文件,复制 build.properties 的内容,并将给定的代码片段插入到 build.gradle 和 settings.gradle 中本机应用程序。最后,我将复制的代码粘贴到本机应用程序的 gradle.properties 中并点击同步。
此时,unityLibrary 模块出现在项目中,但没有任何内容。当尝试构建项目时,它给出了上述错误。
我正在使用 Unity Editor 版本 2023.2.3f1、Android Studio Flamingo 版本 2022.2.1 和 Gradle 版本 8.0.2(我从 7.1.2 更新,试图找到解决方案)
build.gradle 代码如下。
apply plugin: 'com.android.application'
dependencies {
implementation project(':unityLibrary')
implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.games:games-activity:2.0.0'
implementation 'androidx.core:core:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.unity.mynativeapp"
namespace "http://schemas.android.com/apk/res-auto"
minSdkVersion 23
targetSdkVersion 33
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
settings.gradle 如下,
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
include ':app'
include ':unityLibrary'
project(':unityLibrary').projectDir=new File('..\\UnityProject\\androidBuild\\unityLibrary')
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
gradle.properties 代码片段如下,
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs = -Xmx4096M
org.gradle.parallel = true
unityStreamingAssets =
unityTemplateVersion=9
我在这里做错了什么以及如何修复此错误?
我也遇到同样的问题,你解决了吗?