How to properly deal with class dependencies to utilize incremental compilation in Java/Android with Gradle?

守給你的承諾、 提交于 2019-12-02 11:57:42

The problem is in fact that all our classes are part of a big dependency graph. This shows in the quote

Incremental compilation of 476 classes completed in 12.51 secs.

Basically, any class I touch causes a recompilation of 476 classes. In our particular case, this is caused by two patterns. We use Explicit Intents in Android, which I am not sure how to better handle. Additionally, we use Dagger in such a way, that we connected all classes in a circle.

Concerning the interface problematic I made a rather obvious mistake with implementing the cFactory(). As this creates a class dependency from C to B and thus transitively from A to C.

The following snippet breaks the dependency from A to B but creates one from B to A.

public class A{
   public static void foo(C input) {
       input.foo();
   }
}

public class B implements C {
   public void bar() {
       // I make the change here and then trigger a new build
       A.foo(this);
   }
}

public interface C {
   void bar();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!