user3448282
user3448282

Reputation: 2699

Building aar library from multimodule project

I've got a multi-module Android project which have one module called app which is the Android application, that contains features where each feature is separate module.

I would like to extract one of the feature modules as a aar library.

I started from creating a demo app inside the project that have my feature module as a dependency:

implementation project(':player')

I adjusted the code of the app to make it working and in my Demo app inside the project it was working as expected.

My next step was to build the aar file and include it in separate project. I did it by using task:

Gradle -> player -> Tasks -> build -> build

After importing created aar file in new project I'm getting a lot of java.lang.ClassNotFoundException exceptions because classes from modules that player module depends on are not in the generated .jar file.

I didn't mention, but player module depends on few other modules like domain, base-android, data and so on and it seems like all of those modules are not included in aar file.

At first I thought that changing from implementation for those modules to api will solve the problem, but it didn't.

My question is: is there something I'm missing while building the aar library? I thought that if something is working great when included in the module within one project then it should also work like that when after creating a aar file, but it seems like it's not.

Upvotes: 3

Views: 2091

Answers (1)

Mohsina Javaid
Mohsina Javaid

Reputation: 11

You are getting ClassNotFoundException as your module's aar doesn't contains your other submodules' code or aar files. To fix this issue you can check out this gradle plugin that will include all sub modules's arr into your main module automatically. Check out fat AAR, here is the link : https://github.com/kezong/fat-aar-android

Upvotes: 1

Related Questions