Answer the question
In order to leave comments, you need to log in
How to work with recursive dependencies in Android libraries?
Context. There are 3 projects: App
(Android application), Lib
, OuterLib
(Android libraries). The dependency scheme is: Lib
<- OuterLib
<- App
. Lib
contains the class Cls
; OuterLib
contains a function fn
that uses Cls
; App
uses fn
(but does not directly use any of the Lib
).
Problem. Code from App
cannot be executed: an exception is thrown java.lang.NoClassDefFoundError
. Those. the resulting apk does not contain the Cls
. Checked only in tests, without running on an emulator / device. The absence of the required class can be seen during decompilation.
Question.What needs to be done to avoid problems? At the same time, the dependency diagram and the location of the components should remain unchanged. Libraries should remain Android libraries (i.e. compiled into .aar files, not .jars). There App
should be no (explicit) dependency on Lib
.
I tried to play with the scope field when setting up dependencies: I set both Implementation and API to OuterLib
and App
(i.e. I tried 4 options). Dependencies were set through files (i.e. specified specific .aar files without a repository). I used Android Studio 3.0 Canary 4, the code is written in Kotlin (well, this is hardly the cause of the problem)
Answer the question
In order to leave comments, you need to log in
Checked only in tests, without running on an emulator / device.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question