Reputation: 49
I have been trying to generate code in project for a week. The problem is that after i added AppComponent, Module, dependencies and plugin it doesnt work. I got compilation error. Then i repeated all this in new empty project an it works properly. My Android Gradle plugin version:7.1.0 Gradle version:7.3
My AppComponent
@Component(modules = [AppModule::class]) interface AppComponent { fun mainRepository(): MainRepository }
AppModule
@Module object AppModule {
@Provides
fun provideMainRepository(): MainRepository {
return MainRepository()
}
}
Gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
id 'kotlin-kapt'
id 'com.google.firebase.crashlytics'
id 'kotlin-parcelize'
}
android { compileSdkVersion 31 buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.flametech.vaytoday"
minSdkVersion 22
targetSdkVersion 30
versionCode 58
versionName "2.19"
multiDexEnabled = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
viewBinding = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-database:20.0.0'
implementation 'androidx.room:room-runtime:2.3.0'
implementation 'com.google.firebase:firebase-storage-ktx:20.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.databinding:databinding-runtime:4.1.3'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
implementation 'androidx.fragment:fragment-ktx:1.3.6'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
implementation platform('com.google.firebase:firebase-bom:26.0.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-messaging'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
...
implementation "com.google.dagger:dagger:2.40.5"
kapt "com.google.dagger:dagger-compiler:2.40.5"
}
Error
Unresolved reference: DaggerAppComponent
FAILURE: Build failed with an exception.
Compilation error. See log for more details
Stactrace
> Configure project :app
WARNING:The option setting 'android.overridePathCheck=true' is experimental. The current default is 'false'.
Task :app:kaptDebugKotlin app/build/tmp/kapt3/stubs/debug/com/flametech/vaytoday/domain/database/AppDatabase.java:7: warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide
room.schemaLocation
annotation processor argument OR set exportSchema to false. public abstract class AppDatabase extends androidx.room.RoomDatabase { ^
Task :app:compileDebugKotlin FAILED e: app/src/main/java/MainActivity.kt: (51, 42): Unresolved reference: DaggerAppComponent
FAILURE: Build failed with an exception.
Compilation error. See log for more details
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 18s
AppComponent creating in MainActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val appComponent: AppComponent = DaggerAppComponent.create()}
SOLUTION!!!
The problem is solved. I checked my dependencies and understood that i had import in my AppComponent and in my Module like this import com.google.android.datatransport.runtime.dagger.Component
But the right import was import dagger.Component
Upvotes: 1
Views: 707
Reputation: 49
The problem is solved. I checked my dependencies and understood that i had import in my AppComponent and in my Module like this
import com.google.android.datatransport.runtime.dagger.Component
But the right import was import dagger.Component
Upvotes: 1