V
V
van_Kalsing2017-06-20 11:49:36
Android
van_Kalsing, 2017-06-20 11:49:36

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. Libcontains the class Cls; OuterLibcontains a function fnthat uses Cls; Appuses fn(but does not directly use any of the Lib).
Problem. Code from Appcannot 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 Appshould 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 OuterLiband 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

1 answer(s)
A
Alexander Varakosov, 2017-06-21
@thelongrunsmoke

Checked only in tests, without running on an emulator / device.

Most Android API classes are not included in unit tests, because they are executed by the local JVM. The aar libraries are also usually not available.
Write instrumental tests, run them on an emulator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question