I am trying to integrate Unity as a library into my native Android project for a project that I am doing. It will employ Unity application to present the items in native Android application in Augmented Reality.
For that, I was following the [uaal-example/docs/android.md at b41579464b50edf6682a154f3cbb9e098aa5ba3d · Unity-Technologies/uaal-example · GitHub] to get started.
However, despite following the steps mentioned, I am unable to properly add unityLibrary to my native Android application. Even though the “unityLibrary” module appears in my project’s tree as below,
it does not include the respective assets, resources and the classes as it should,
Even though the Gradle syncs when I try to build the project, I get the following error.
"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."
I am mostly new to Unity developing and to programming itself and currently have no idea what I’m doing wrong here. I followed through the steps, setting up the Unity project through build settings and project settings, generating the Gradle file by exporting, copying the contents of build.properties, and inserting the given code snippets in the build.gradle and settings.gradle of the native application. Then finally, I pasted the copied code in the native application’s gradle.properties and hit sync.
That’s when the unityLibrary module appears in the project without any of its contents. When tried to build the project, it gives the mentioned error.
I am using Unity Editor version 2023.2.3f1, Android Studio Flamingo version 2022.2.1 and Gradle version 8.0.2 (which I updated from 7.1.2 trying to find a solution)
The build.gradle code is below.
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'
}
}
}
The settings.gradle is as,
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"
}
}
}
The gradle.properties code snippet is as,
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs = -Xmx4096M
org.gradle.parallel = true
unityStreamingAssets =
unityTemplateVersion=9
What am I doing wrong here and how to fix this error?