As I'm sure you're aware, Android is sensitive to method count and accessing private members across nested class boundaries causes javac to create synthetic accessor methods. Dagger subcomponents are implemented using nested classes in the generated source. These subcomponents access providers from the enclosing component which are stored in private fields. As a result, lots of synthetic accessor methods are created when subcomponents are used.
A simple fix here is to make all fields package-private.
While this does increase the visibility, user code never references subcomponent implementation instances directly where they could potentially access them. We only reference the static builder() and the nested Builder class. The Builder's build() method returns the interface type, not the implementation type. While you could in theory cast back to the implementation type, doing so is highly unlikely and isn't really different than your ability to use reflection to get at the fields currently.
For some numbers, a small app using Dagger with a large component and two medium-sized subcomponents receives ~100 of these synthetic accessor methods. Square Register, a non-trivial large app, receives ~1000 of these synthetic accessor methods which itself is larger than some of the third-party libraries it uses and nearly 2% of the 65k single dex limit.
As I'm sure you're aware, Android is sensitive to method count and accessing private members across nested class boundaries causes javac to create synthetic accessor methods. Dagger subcomponents are implemented using nested classes in the generated source. These subcomponents access providers from the enclosing component which are stored in private fields. As a result, lots of synthetic accessor methods are created when subcomponents are used.
A simple fix here is to make all fields package-private.
While this does increase the visibility, user code never references subcomponent implementation instances directly where they could potentially access them. We only reference the static
builder()and the nestedBuilderclass. TheBuilder'sbuild()method returns the interface type, not the implementation type. While you could in theory cast back to the implementation type, doing so is highly unlikely and isn't really different than your ability to use reflection to get at the fields currently.For some numbers, a small app using Dagger with a large component and two medium-sized subcomponents receives ~100 of these synthetic accessor methods. Square Register, a non-trivial large app, receives ~1000 of these synthetic accessor methods which itself is larger than some of the third-party libraries it uses and nearly 2% of the 65k single dex limit.