How to avoid a class dependency monolith using Int

2019-08-19 16:31发布

问题:

As I describe in this question I can not utilize Gradle's incremental compilation properly, as almost our whole codebase is dependent on each other. This causes almost 500 classes to compile all the time.

I found out that many of the class dependencies are caused by the use of explicit Intents like such:

Intent intent = new Intent(context, NewActivity.class);

This creates a class dependency from the current class to NewActivity. Connecting activities in this way quickly form a class dependency monolith. At least a big tree if there are no cycles unless there is something I miss here. (Cycles are common, aren't they?)

I am aware that this may be avoided through the use of Implicit Intents, but as far as I understand this is not the proposed use case for them. In fact, Explicit Intents don't have unnecessary boilerplate code and offer compile-time checks.

I wonder what the proper way is to deal with this issue. Or is this the proper (or at least common) way and incremental compilation is more of a myth among Android developers?