Forum für diejenigen, die für Android programmieren
Anonymous
Dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelfactory 'konnte nicht aufgelöst werden- Android Kotlin
Post
by Anonymous » 28 Feb 2025, 09:05
Detailfehler
componentprocessingStep konnte nicht verarbeiten. />
Anwendungsklasse < /strong> < /p>
Code: Select all
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class BaseApp : Application()
App Gradel -Datei [/b]
Code: Select all
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
kotlin("kapt")
id("dagger.hilt.android.plugin")
}
android {
namespace = "com.example.daggerhilt"
compileSdk = 33
defaultConfig {
applicationId = "com.example.daggerhilt"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}
dependencies {
implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
// Coroutines
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.google.hilt.android)
kapt(libs.hilt.compiler)
implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.hilt.lifecycle.viewmodel)
implementation (libs.androidx.lifecycle.viewmodel.ktx)
implementation (libs.androidx.lifecycle.livedata.ktx)
//retrofit
implementation(libs.gson)
implementation(libs.retrofit)
implementation(libs.converter.gson)
implementation(libs.logging.interceptor)
}
kapt {
correctErrorTypes = true
}
< /code>
** Gradel -Datei der Projektebene ** < /p>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.kotlinAndroid) apply false
}
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath(libs.gradle)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.hilt.android.gradle.plugin)
}
}
true // Needed to make the Suppress annotation work for the plugins block
< /code>
** App -Moduldatei ** < /p>
package com.example.daggerhilt.di
import com.example.daggerhilt.Network.ApiService
import com.example.daggerhilt.Network.HeaderInterceptor
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides
@Singleton
fun getBaseUrl() = "https://jsonplaceholder.typicode.com/"
@Provides
@Singleton
fun getIsAddedToken() = true
@Provides
@Singleton
fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY) // Set the desired log level
return loggingInterceptor
}
@Provides
@Singleton
fun provideHeaderInterceptor(isAddedToken: Boolean): HeaderInterceptor {
return HeaderInterceptor(isAddedToken)
}
@Provides
@Singleton
fun provideOkHttpClient(
httpLoggingInterceptor: HttpLoggingInterceptor,
headerInterceptor: HeaderInterceptor
): OkHttpClient {
val builder = OkHttpClient.Builder()
builder.addInterceptor(httpLoggingInterceptor)
builder.addInterceptor(headerInterceptor)
return builder.build()
}
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient, baseUrl: String): Retrofit {
return Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
}
@Provides
@Singleton
fun provideApiService(retrofit: Retrofit): ApiService {
return retrofit.create(ApiService::class.java)
}
}
< /code>
** apiservice ** < /p>
interface ApiService {
@GET("posts")
suspend fun getPost(): List
}
class ApiServiceImp @Inject constructor(val apiService: ApiService) {
suspend fun getPost(): List = apiService.getPost()
}
1740729940
Anonymous
[b] Detailfehler [/b] componentprocessingStep konnte nicht verarbeiten. /> [b] Anwendungsklasse < /strong> < /p> [code]import android.app.Application import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class BaseApp : Application() [/code] App Gradel -Datei [/b] [code] @Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { alias(libs.plugins.androidApplication) alias(libs.plugins.kotlinAndroid) kotlin("kapt") id("dagger.hilt.android.plugin") } android { namespace = "com.example.daggerhilt" compileSdk = 33 defaultConfig { applicationId = "com.example.daggerhilt" minSdk = 24 targetSdk = 33 versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = "17" } } dependencies { implementation(libs.core.ktx) implementation(libs.appcompat) implementation(libs.material) implementation(libs.constraintlayout) testImplementation(libs.junit) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.espresso.core) // Coroutines implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.coroutines.core) implementation(libs.google.hilt.android) kapt(libs.hilt.compiler) implementation(libs.androidx.activity.ktx) implementation(libs.androidx.hilt.lifecycle.viewmodel) implementation (libs.androidx.lifecycle.viewmodel.ktx) implementation (libs.androidx.lifecycle.livedata.ktx) //retrofit implementation(libs.gson) implementation(libs.retrofit) implementation(libs.converter.gson) implementation(libs.logging.interceptor) } kapt { correctErrorTypes = true } < /code> ** Gradel -Datei der Projektebene ** < /p> // Top-level build file where you can add configuration options common to all sub-projects/modules. @Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { alias(libs.plugins.androidApplication) apply false alias(libs.plugins.kotlinAndroid) apply false } buildscript { repositories { google() mavenCentral() } dependencies { classpath(libs.gradle) classpath(libs.kotlin.gradle.plugin) classpath(libs.hilt.android.gradle.plugin) } } true // Needed to make the Suppress annotation work for the plugins block < /code> ** App -Moduldatei ** < /p> package com.example.daggerhilt.di import com.example.daggerhilt.Network.ApiService import com.example.daggerhilt.Network.HeaderInterceptor import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object AppModule { @Provides @Singleton fun getBaseUrl() = "https://jsonplaceholder.typicode.com/" @Provides @Singleton fun getIsAddedToken() = true @Provides @Singleton fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor { val loggingInterceptor = HttpLoggingInterceptor() loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY) // Set the desired log level return loggingInterceptor } @Provides @Singleton fun provideHeaderInterceptor(isAddedToken: Boolean): HeaderInterceptor { return HeaderInterceptor(isAddedToken) } @Provides @Singleton fun provideOkHttpClient( httpLoggingInterceptor: HttpLoggingInterceptor, headerInterceptor: HeaderInterceptor ): OkHttpClient { val builder = OkHttpClient.Builder() builder.addInterceptor(httpLoggingInterceptor) builder.addInterceptor(headerInterceptor) return builder.build() } @Provides @Singleton fun provideRetrofit(okHttpClient: OkHttpClient, baseUrl: String): Retrofit { return Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClient) .build() } @Provides @Singleton fun provideApiService(retrofit: Retrofit): ApiService { return retrofit.create(ApiService::class.java) } } < /code> ** apiservice ** < /p> interface ApiService { @GET("posts") suspend fun getPost(): List } class ApiServiceImp @Inject constructor(val apiService: ApiService) { suspend fun getPost(): List = apiService.getPost() } [/code]
0 Replies
2 Views
Last post by Anonymous
28 Feb 2025, 09:26
0 Replies
7 Views
Last post by Guest
14 Jan 2025, 12:49
0 Replies
15 Views
Last post by Anonymous
14 Apr 2025, 20:13
0 Replies
15 Views
Last post by Guest
25 Dec 2024, 20:23
0 Replies
23 Views
Last post by Guest
03 Jan 2025, 17:58