Search code examples
androidkotlinandroid-jetpack-composeandroid-librarykotlin-multiplatform

Nested dependencies or library are not available in generated AAR , Unable to import the class or library used in module to root project


Hi I'm new to android developed, So please excuse any basic mistakes

Developing a KMM project and need to include this as an external dependencies in another project

So converted this KMM project a library (AAR)

After adding this as an dependencies to another native compose project the compose function of android KMM is available to call from root(parent) project and the UI also rendering but the problem is the module of KMM shared class are not available to import.

just to cross-check I have added the aar of the shared module into the root project then it's available to import .

My question is since the KMM android project has the included the shared module of KMM in it's dependencies build.gradle and in settings.gradle.kts why does the aar of KMM android does not include the nested dependencies or it's own external dependencies like koin, coil , ktor

Error

Caused by: java.lang.ClassNotFoundException: Didn't find class "coil.compose.SingletonAsyncImageKt" on path: DexPathList[[zip file "/data/app/~~Xr86WRb8oZvcDEMKe2nugA==/com.kobil.integratelibrary-NZ1-2io6hAVQ8eDJK4wSXg==/base.apk"],nativeLibraryDirectories=[/data/app/~~Xr86WRb8oZvcDEMKe2nugA==/com.kobil.integratelibrary-NZ1-2io6hAVQ8eDJK4wSXg==/lib/arm64, /system/lib64, /system_ext/lib64]]

Root(parent) project which has AAR under libs inside app module , And using the compose funs of module in mainActivity enter image description here

KMM project made changes done from application to library and it's working fine, the UI is rendering in root project which is declared in KMM android activity. enter image description here

Ran this on terminal to generate AAR ./gradlew assembleRelease


Solution

  • I'm answering my own question and uploaded a sample solution in repo https://github.com/Prathiv07/KMMasModule

    Issue with Uploading a Library to Maven: Nested Module Not Available in Final AAR

    I've been facing an issue while uploading a library to Maven. The structure of my project is as follows:

    Library app module: Originally an application, I converted it to a library that needs to be used in another project. this module use the shared module

    shared module: Contains business logic and default libraries.

    When I generate an AAR for the app module and use it in another project, the shared module is not found, leading to issues. I tried various solutions, including adding POM dependencies, but none worked.

    Finally, I resolved the issue by uploading both the app module AAR and the shared module AAR to Maven. After doing this, the final AAR library worked fine.