Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How add more than one aar file in build.gradle?

Tags:

gradle

aar

I created a 'base_lib' module where saves 2 aar files and a build.gradle file. This is how my build.gradle looks: Let's say, 2 aar files are A.aar and B.aar:

configurations.create("default")
artifacts.add("default", file('A.aar'))
artifacts.add("default", file('B.aar'))

Now, I have another 2 modules, called AModule and BModule, both these 2 modules have implemented this 'base_lib'. In this case, Both AModule and BModule can be compiled without errors and successfully compiled.

But when I open the B.kt file where reference classes from B.aar in BModule, a lot of errors are showing inside. I thought it's a cache problem but after I clear all cache, the problem is still here.

So I changed these 2 lines position:

configurations.create("default")
artifacts.add("default", file('B.aar'))
artifacts.add("default", file('A.aar'))

Now, B.kt file has not errors but when I open the A.kt file in the AModule, it has the same problem like B was.

So, which aar I put below, the file reference to it showing "can't find class" errors(Anyway, it doesn't matter to compile).

Is any way to make both AModule and BModule can reference classes from both these aar files correctly?

like image 278
Licat Julius Avatar asked Dec 06 '25 07:12

Licat Julius


1 Answers

I got a way to do, just create a module, let's call it as base_lib, and put all your aars inside. All other modules implemate it. This is how my build.gradle file looks. enter image description here

plugins {
    id 'java-library'
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
    api fileTree(include: ['*.aar'], dir: 'libs')
}
like image 184
Licat Julius Avatar answered Dec 09 '25 20:12

Licat Julius



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!