Компонент Dagger 2 не генерируется - PullRequest
0 голосов
/ 13 мая 2019

В моем модуле, в моем классе BaseApp

class BaseApp : Application() {

    companion object {
        lateinit var appComponent: AppComponent
        val baseUrl = "https://api.github.com/"
    }

    override fun onCreate() {
        super.onCreate()

        appComponent = DaggerAppComponent.builder()
            .networkModule(NetworkModule(baseUrl))
            .apiModule(ApiModule())
            .appModule(AppModule(this))
            .localModule(LocalModule(this))
            .build()
    }
}

он не может найти DaggerAppComponent.

Что может быть причиной не генерирования компонента кинжала. класс?

Это мои модули классов

Это ApiModule.

@Module
class ApiModule{

    @Provides
    @Singleton
    fun provideApi(@Named("retrofit") retrofit: Retrofit) : API = retrofit.create(API::class.java)

    @Provides
    @Singleton
    fun provideApiClient(Api: API) = ApiClient(Api)

}

Это AppModule

@Module
class AppModule(val application: Application) {
    @Provides
    @Singleton
    fun provideApp() = application
}

Это LocalModule

@Module
class LocalModule(val application: Application) {

    private val authDatabase: AuthDatabase

    init {
        authDatabase = Room.databaseBuilder(application, AuthDatabase::class.java, "auth.db").build()
    }
    @Provides
    @Singleton
    fun provideLocalStorage() = SharedPrefStorage(application)

    @Singleton
    @Provides
    fun provideRoomDatabase(): AuthDatabase = authDatabase

    @Singleton
    @Provides
    fun provideAuthDao(authDatabase: AuthDatabase): AuthDao = authDatabase.getAuthDao()
}

Это NetworkModule

@Module
class NetworkModule(val mBaseUrl: String) {

    @Provides
    @Singleton
    fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor = HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY }

    @Provides
    @Singleton
    fun provideSecretHeaderInterceptor(local: LocalStorage, authDatabase: AuthDatabase): SecretHeaderInterceptor = SecretHeaderInterceptor(local, authDatabase)

    @Provides
    @Singleton
    fun provideOkHttpClient(loggingInterceptor: HttpLoggingInterceptor, secretHeaderInterceptor: SecretHeaderInterceptor): OkHttpClient {
        return OkHttpClient.Builder()
            .addInterceptor(loggingInterceptor)
            .addInterceptor(secretHeaderInterceptor)
            .build()
    }

    @Provides
    @Singleton
    fun provideGson(): Gson {
        return GsonBuilder().create()
    }


    @Provides
    @Singleton
    @Named("retrofit")
    fun provideRetrofit(gson : Gson, okHttpClient: OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl(mBaseUrl)
            .client(okHttpClient)
            .build()
    }

}

А это мой класс Компонентов

@Singleton
@Component(modules = [(AppModule::class),(NetworkModule::class),(ApiModule::class),(LocalModule::class)])
interface AppComponent{

    fun inject(extensionStudyActivity: ApplyExtensionStudyActivity)

    fun inject(applyStayingActivity: ApplyStayingActivity)

    fun inject(changePasswordActivity: ChangePasswordActivity)

    fun inject(noticeActivity: NoticeActivity)

    fun inject(pointLogActivity: PointLogActivity)

    fun inject(registerActivity: RegisterActivity)

    fun inject(signInActivity: SignInActivity)

    fun inject(splashActivity: SplashActivity)

    fun inject(applyMusicDialogFragment: ApplyMusicDialogFragment)

    fun inject(bugReportDialogFragment: BugReportDialogFragment)

    fun inject(institutionDialogFragment: InstitutionDialogFragment)

    fun inject(logoutDialogFragment: LogoutDialogFragment)

    fun inject(applyGoingFragment: ApplyGoingFragment)

    fun inject(applyGoingDocFragment: ApplyGoingDocFragment)

    fun inject(applyGoingEditFragment: ApplyGoingEditFragment)

    fun inject(applyGoingLogFragment: ApplyGoingLogFragment)

    fun inject(applyMusicFragment: ApplyMusicFragment)

    fun inject(applyMusicLogFragment: ApplyMusicLogFragment)

    fun inject(mealFragment: MealFragment)

    fun inject(myPageFragment: MyPageFragment)

    fun inject(noticeDescriptionFragment: NoticeDescriptionFragment)

    fun inject(putInFragment: PutInFragment)
}

Что я должен делать? решите пожалуйста ...

1 Ответ

0 голосов
/ 13 мая 2019

Удалите весь код реализации dagger2 и замените его ниже.

def final dagger_version = '2.22.1'
implementation "com.google.dagger:dagger:${dagger_version}"
implementation "com.google.dagger:dagger-android:${dagger_version}"
implementation "com.google.dagger:dagger-android-support:${dagger_version}"
kapt "com.google.dagger:dagger-compiler:${dagger_version}"
kapt "com.google.dagger:dagger-android-processor:${dagger_version}"

и применить apply plugin: 'kotlin-kapt' в Gradle.

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
...