Hi community, I am a Unity dev who has built an Android library (.aar) to extend Unity’s functionality. This worked fine so far. My library needs some external dependencies, however. When I build my .aar, these dependencies won’t be added to my .aar file, so I used to add their .aar files manually to Unity. But this is quite cumbersome, and it’s not easy to find the .aar files of some of the dependencies only, because most developers assume that they’re just used as dependencies in the build.gradle file.
This is why I am trying to bundle the dependencies right in my own .aar file, to get everything together in one place. However, I am struggling a lot in achieving this. I find gradle to be super complex at the least, and most of the info I get on stackoverflow seems to be outdated, due to frequent changes in gradle. I also tried to ask ChatGPT for help, but the suggestions were also not working properly.
So I am trying my luck here, with “real humans”.
Ideally, the libaries would become part of my .aar file, so I have to deal with only one .aar in Unity. However, it would also be fine to copy the .aars to a folder so I can retrieve them from there without trying to find out where I can find them online or how I could build them myself.
For copying them, I tried this approach that I found online:
task copyDependencies(type: Copy) {
from configurations.implementation
into "$buildDir/outputs/aar/dependencies"
}
but this resulted in the error
Resolving dependency configuration 'implementation' is not allowed as it is defined as 'canBeResolved=false'.
Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'implementation' should be resolved.
if I run this task separately.
If I try the same as dependency on build (build.dependOn), it works, but I still do not get any aars copied to the folder.
Here’s my build.gradle file:
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.marblear.marbleextensions'
compileSdk 33
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdk 24
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
compileOnly files('libs/classes.jar')
// I need to embed these or at least copy their .aar files:
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.loopj.android:android-async-http:1.4.8'
implementation "net.gotev:uploadservice:4.8.0"
implementation "net.gotev:uploadservice-okhttp:4.8.0"
}
The libraries I want to bundle with my .aar (or copy to a folder at least) are the ones listed below compileOnly
. The compileOnly
thing is needed to compile my own code against the Unity libraries (libs/classes.jar)
Thanks in advance.