Dagger 2.2 컴포넌트 빌더 모듈 메소드가 더 이상 사용되지 않음
dagger 2.2를 사용하기 시작했고 컴포넌트 빌더의 모듈 메소드는 더 이상 사용되지 않습니다.
이것은 내 응용 프로그램 구성 요소입니다.
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
void inject(Application application);
}
그리고 애플리케이션 모듈 :
@Module
public class ApplicationModule {
Application application;
public ApplicationModule(Application application) {
this.application = application;
}
@Provides
@Singleton
Application providesApplication() {
return application;
}
}
생성 된 클래스는 다음과 같습니다.
@Generated(
value = "dagger.internal.codegen.ComponentProcessor",
comments = "https://google.github.io/dagger"
)
public final class DaggerApplicationComponent implements ApplicationComponent {
private DaggerApplicationComponent(Builder builder) {
assert builder != null;
}
public static Builder builder() {
return new Builder();
}
public static ApplicationComponent create() {
return builder().build();
}
@Override
public void inject(Application application) {
MembersInjectors.<Application>noOp().injectMembers(application);
}
public static final class Builder {
private Builder() {}
public ApplicationComponent build() {
return new DaggerApplicationComponent(this);
}
/**
* @deprecated This module is declared, but an instance is not used in the component. This method is a no-op. For more, see https://google.github.io/dagger/unused-modules.
*/
@Deprecated
public Builder applicationModule(ApplicationModule applicationModule) {
Preconditions.checkNotNull(applicationModule);
return this;
}
}
}
ComponentBuilder를 사용하지 않는 경우 구성 요소를 어떻게 초기화합니까?
더 이상 사용되지 않는 이유에 대한 설명을 읽어야합니다 . IntelliJ 또는 Android Studio와 같은 IDE를 사용하는 경우 방법을 선택하고 Windows에서 Control+ Q를 눌러 지원 중단 알림을 포함한 Javadoc을 읽을 수 있습니다.
Javadoc은 다음을 읽습니다.
@deprecated이 모듈은 선언되었지만 구성 요소에서 인스턴스가 사용되지 않습니다. 이 방법은 작동하지 않습니다. 자세한 내용은 https://google.github.io/dagger/unused-modules를 참조 하십시오 .
이 링크에서 다음을 볼 수 있습니다.
When the Dagger processor generates components, it only requires instances of modules and component dependencies that are explicitly needed to supply requests for a binding.
- If all of a module’s methods that are used in the component are static, Dagger does not need an instance of that module at all. Dagger can invoke the static methods directly without a module.
- If a module provides no bindings for a Component, no instance of that module is necessary to construct the graph.
It is safe to say that you can just ignore the deprecation. It is intended to notify you of unused methods and modules. As soon as you actually require / use Application
somewhere in your subgraph the module is going to be needed, and the deprecation warning will go away.
It show deprecated because you are not using Component and module in your application by
@Inject
SomeObjectFromModule mSomeObject
if you are not injecting dependencies in your applications there is no use of initialising your component so dagger look for at least one usage
once you add these lines in any classes you want to inject views and then clean build and rebuild the project and your deprecation will be solved
It showing error when my Module
have no @Provides
method or the object that provide by Dagger
is not used in app.
Example to remove deprecated module
Module
@Module
public class SecondActivityModule {
@Provides
Book provideBookTest() {
return new Book();
}
}
Activity
public class SecondActivity extends AppCompatActivity {
@Inject
Book test;
...
}
OR in Component
@Component(modules = SecondModule.class)
public interface SecondComponent {
void inject(SecondActivity activity);
Book getBookTest();
}
I have the same problem with host and I just want everyone has deprecated issue on Generated component builder class should check two things to save time:
1/ Correct dagger syntax for module, component also check carefully where you inject.
2/ Must have injection object (inject annotation and its object) in place you want to inject or else the dagger compiler cannot see where to use your module so some method will be deprecated.Just inject at least one module's provides to your injection place and re-compile the code, you won't have that issue anymore :)
참고URL : https://stackoverflow.com/questions/36521302/dagger-2-2-component-builder-module-method-deprecated
'program tip' 카테고리의 다른 글
현재 컨텍스트에 'controlname'이름이 없습니다. (0) | 2020.10.28 |
---|---|
Python에서 범위를 벗어난 인덱스에 대한 기본값 가져 오기 (0) | 2020.10.28 |
Python을 사용하여 Microsoft SQL 서버에 연결 (0) | 2020.10.28 |
Docker를 1.12로 업데이트 한 후 이미지를 가져 오기 / 푸시 할 수 없음 (0) | 2020.10.28 |
HttpWebRequest는 매우 느립니다! (0) | 2020.10.28 |