i am facing issue from last 2 days. Currently , i am using Android studio Giraffe version. i am unable to get daggerComponent class. here is my code .
this is my app level gradle file
` plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-android")
id("kotlin-kapt")
}
android {
namespace = "com.example.myapplication"
compileSdk = 34
defaultConfig {
applicationId = "com.example.myapplication"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
kapt{
generateStubs=true
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
kapt ("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.7.0")
implementation("com.google.dagger:dagger:2.48")
implementation("com.google.dagger:dagger-android:2.48")
implementation("com.google.dagger:dagger-android-support:2.48")
annotationProcessor("com.google.dagger:dagger-compiler:2.48")
// kapt ("com.google.dagger:dagger-compiler:2.48")
annotationProcessor("com.google.dagger:dagger-android-processor:2.48")
kapt("com.google.dagger:dagger-android-processor:2.48")
compileOnly("org.glassfish:javax.annotation:10.0-b28")
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jre7:1.9.0")
compileOnly("javax.annotation:jsr250-api:1.0")
implementation("javax.inject:javax.inject:1")
}`
NOTE:- those dependencies which i did comment is actually showing me error while rebuild.
Here is my Project level gradle file
`// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins {
id("com.android.application") version "8.1.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}`
and Here is my component interface
@Singleton
@Component(modules = \[NetworkModule::class\])
interface ApplicationComponent {
fun inject(mainActivity: MainActivity)
}
and this is the class where i want to call DaggerComponent class
class FakerApplication : Application() {
lateinit var applicationComponent: ApplicationComponent
override fun onCreate() {
super.onCreate()
}
}
I have tried all stackoverflow's answer but not getting any benefit. whenever i am trying to implement kapt dependency it is showing me error. help me to resolve this issue. Thankyou
From the README.md printed on https://github.com/google/dagger, in the Gradle section's Notes:
For Kotlin projects, use
kapt
in place ofannotationProcessor
.
The Gradle file in your question contains both annotationProcessor
and kapt
lines for both com.google.dagger:dagger-compiler:2.48
and com.google.dagger:dagger-android-processor:2.48
. As in this question, your build will work fine for both Java and Kotlin if you use just the kapt
lines instead of annotationProcessor
lines for both dagger-compiler
and dagger-android-processor
.
There might be other reasons that your build is failing, and pasting your error message into your question may help with further diagnosis. However, in any case, you are not intended to include both the annotationProcessor
and kapt
lines for the same processor.
Note for future readers: As of September 2023, kapt is in maintenance mode, to be replaced by Kotlin Symbol Processing (KSP). Dagger 2.48 is the first release to contain an alpha release of Dagger's KSP processor and corresponding KSP documentation.