如何正确使用类依赖性处理利用领域是Java / Android的增量编译与摇篮?

问题描述 投票:0回答:1

我改进了构建系统,并在this问题描述激活增量构建和编译。令我失望的是,渐进式编译没有改善的构建时间,因为我从阅读Gradles blog post预期的那样多。

经过一番调查后,我意识到,问题是,即使我只是在应用程序添加注释,以小班深的地方显然是几乎整个代码库重建。事实上,它并不真正的问题,我摸着哪一个类,Gradles --debug输出显示,它基本上总是重新编译类476。

476班的渐进式编译在12.51秒完成。

虽然我知道在改变文件public static常量触发完全重新编译(这是唯一稍微慢一些),我不知道如何正确地分手类依赖性,使增量编译实际工作。什么是确切的规则,以确定影响的渐进式编译类依赖性?我可以读到一些例子here,但它似乎并不适用于我们(相当标准)项目在所有。

我自己的一些testings的产生如下:

// One of my main classes that has lots of class dependencies
public class A{
   public void foo() {
       // This line produces a dependency between A and B. So changing just
       // a comment in B triggers recompilation of all classes attached to A
       B b1 = new B(); 


   }
}

// A small helper class that I want to change
public class B {
   public void bar() {
       // This line does not create a dependency, so B can still be compiled by
       // itself. But usually, that's not the "common" direction you have.
       A a1 = new A();
       // I make the change here and then trigger a new build
   }
}

为什么当一个实现细节,而不是B的界面改变,需要重新编译?

我也尝试背后的接口C.“隐藏” B我认为这会是正确的(尽管很多时候非常麻烦)的方式,打破了依赖。但事实证明,它并没有帮助的。


public class A{
   public void foo() {
       C c1 = C.cFactory();
   }
}

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

public interface C {
   void bar();

   public static C cFactory() {
       return new B();
   }
}

在我看来,我们有这么大的依赖性blob和我不确定,即使我认为我们有一个合理设计的代码库,这可能合理地改变。有没有最佳实践,指导方针或设计图案,Android开发,将有效地提高增量编译中常见的?

我不知道其他人是否有同样的问题,因为我们做的,如果不是你做了什么?

java android gradle android-studio-3.0 incremental-compiler
1个回答
0
投票

问题是事实,我们的所有的类都是一个很大的依赖关系图的一部分。这说明在报价

476班的渐进式编译在12.51秒完成。

基本上,我触摸任何类导致476类的重新编译。在我们的特定情况下,这是由两种模式造成的。我们用显式意图在Android中,which I am not sure how to better handle。此外,我们用匕首以这样的方式,我们连接了一圈的所有类。

关于接口问题我做了一个比较明显的错误与实施cFactory()。因为这会产生一类依赖从qaz​​xswpoi从C B并因此传递地到A

下面的代码片段从突破到CA依赖而造成一个从BB

A
© www.soinside.com 2019 - 2024. All rights reserved.