У меня есть два объекта, которые я без проблем ввожу с помощью dagger2. Когда я добавляю третий (так же, как и два ранее), проект не перестраивается и выдает ошибки, указывающие на первые два (здесь ничего не говорится о добавлении третьего):
error: com.google.firebase.database.DatabaseReference cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
com.google.firebase.database.DatabaseReference is injected at
com.hotmail.at.jablonskimichal.dni.wolne.od.handlu.ui.splash.SplashPresenter.freeDaysCloudReference
com.hotmail.at.jablonskimichal.dni.wolne.od.handlu.ui.splash.SplashPresenter is injected at
com.hotmail.at.jablonskimichal.dni.wolne.od.handlu.providers.components.MainPresenterComponent.inject(destination)
Каждые три модуля и компонента реализованы одинаково. Конечно, когда я удаляю добавленную третью, проекты легко компилируются.
Модуль, который портит сборку проекта:
@Module
public class MainPresenterModule {
private final MainPresenter presenter;
public MainPresenterModule(MainPresenter presenter) {
this.presenter = presenter;
}
@Singleton
@Provides
MainPresenter provideMainPresenter() {
return presenter;
}
}
Составная часть:
@Singleton
@Component(modules = {MainPresenterModule.class})
public interface MainPresenterComponent {
void inject(SplashPresenter destination);
}
Может быть полезно: Я использую эти библиотеки для DI с dagger2:
implementation 'com.google.dagger:dagger-android:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
с новейшей студией Android (3.1.1) и gradle (3.1.1) на Mac OSX. Конечно, я пробовал аннулировать кеш и перезагружать, очищать и т. д. Я проверил импорт, и все они одинаковы.
Редактировать: Когда я прекращаю использование инъекции
@Inject
DatabaseReference shopsCloudReference;
public MainPresenter(MainController controller) {
super(controller);
Core.injectShopsComponent().into(this);
}
А также
@Inject
DatabaseReference freeDaysCloudReference;
public SplashPresenter(SplashController controller) {
super(controller);
Core.injectFreeDaysComponent().into(this);
}
проект компилируется, но это не то, что я хотел.
РЕДАКТИРОВАТЬ Есть много ответов, что я не добавлял библиотеки firebase в gradle. Моя полная оценка:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.hotmail.at.jablonskimichal.dni.wolne.od.handlu"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
allprojects {
repositories {
mavenCentral()
google()
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//support
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
//images loading
implementation 'com.github.bumptech.glide:glide:4.4.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'
//network
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.2.0'
//json parsing
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.google.code.gson:gson:2.8.0'
//for view bindings
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//rxjava
def rxVersion = '2.0.2'
implementation "io.reactivex.rxjava2:rxandroid:$rxVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxVersion"
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
//dagger
implementation 'com.google.dagger:dagger-android:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
//google
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.firebase:firebase-database:15.0.0'
implementation 'com.google.firebase:firebase-core:15.0.0'
//datetime
implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'
//transitions
implementation "com.andkulikov:transitionseverywhere:1.7.9"
//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
почему в ошибке написано firebase? вы используете firebase? это не отображается в ваших зависимостях ...
Кроме того, какой третий объект вы пытаетесь ввести?
Я использую два объекта базы данных firebase, и он хорошо работает, пока не добавлю третий объект DI, который является MainPresenter.class. Все они реализуются одинаково.
@ADM Я только что добавил настраиваемые области, и это не помогло
Пожалуйста, посмотрите Как исправить не может быть предоставлено для получения дополнительной информации. Вы нигде не предоставляете DatabaseReference, поэтому Dagger не может его ввести.




Ну вы написали:
@Component(modules = {MainPresenterComponent.class})
Так должно быть :
@Component(modules = {MainPresenterModule.class})
Ох .. Я видел это раньше, но скопировал не тот текст. Ошибка относится к соответствующему классу. Я редактировал вопрос. Простите
Как отметил @Levi_Albuquerque, вы пытаетесь ввести DatabaseReference, но он не отображается в ваших зависимостях
Есть, но я об этом не упоминал.
Вероятно, вам стоит «упомянуть об этом», учитывая, что это важно для ответа на вопрос.