인프런 커뮤니티 질문&답변

Bruce님의 프로필 이미지

작성한 질문수

냉동코더의 알기 쉬운 Modern Android Development 입문

Practice2D-검색결과를 UI에 표시하기 (Coil, ListAdapter, SaveStateHandle)

Moshi 관련 Exception error

작성

·

1K

0

2022-12-12 09:04:14.193 11869-11909/com.example.booksearchapp E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.example.booksearchapp, PID: 11869
    java.lang.IllegalArgumentException: Unable to create converter for class com.example.booksearchapp.data.model.SearchResponse
        for method BookSearchApi.searchBooks
        at retrofit2.Utils.methodError(Utils.java:54)
        at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:126)
        at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:85)
        at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
        at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
        at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
        at $Proxy2.searchBooks(Unknown Source)
        at com.example.booksearchapp.data.repository.BookSearchRepositoryImpl.searchBooks(BookSearchRepositoryImpl.kt:14)
        at com.example.booksearchapp.ui.viewmodel.BookSearchViewModel$searchBooks$1.invokeSuspend(BookSearchViewModel.kt:18)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
    	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@5775e41, Dispatchers.IO]
    Caused by: java.lang.RuntimeException: Failed to find the generated JsonAdapter class for class com.example.booksearchapp.data.model.SearchResponse
        at com.squareup.moshi.internal.Util.generatedAdapter(Util.java:590)
        at com.squareup.moshi.StandardJsonAdapters$1.create(StandardJsonAdapters.java:61)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:146)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:106)
        at retrofit2.converter.moshi.MoshiConverterFactory.responseBodyConverter(MoshiConverterFactory.java:89)
        at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:362)
        at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:345)
        at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:124)
        	... 16 more
     Caused by: java.lang.ClassNotFoundException: com.example.booksearchapp.data.model.SearchResponseJsonAdapter
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at com.squareup.moshi.internal.Util.generatedAdapter(Util.java:564)
        	... 23 more
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.booksearchapp.data.model.SearchResponseJsonAdapter" on path: DexPathList[[zip file "/data/app/~~ewlJIwWx_qkVa9ZkFq_uYw==/com.example.booksearchapp-D0tkT_fBZhzV4uo7HrITvw==/base.apk"],nativeLibraryDirectories=[/data/app/~~ewlJIwWx_qkVa9ZkFq_uYw==/com.example.booksearchapp-D0tkT_fBZhzV4uo7HrITvw==/lib/x86_64, /system/lib64, /system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        	... 26 more

SearchFragment에 RecyclerView와 searchBooks를 추가 한뒤 빌드하여 검색창에 텍스트를 입력하면 앱이 바로 죽는 현상이 나타나고 있어 질문드립니다.

Moshi에서 JasonAdapter를 찾을 수 없다고 하는데 혹시 의존성 세팅이 다르게 되어 있어서일까요?

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    /*add ksp*/
    id("com.google.devtools.ksp").version("1.6.10-1.0.4")
    id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.booksearchapp"
        minSdk 23
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled 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'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

    /* Retrofit */
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'

    /* Moshi */
    implementation 'com.squareup.moshi:moshi:1.13.0'
    implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
    ksp("com.squareup.moshi:moshi-kotlin-codegen:1.14.0")

    /* Okhttp */
    implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
    implementation("com.squareup.okhttp3:okhttp")
    implementation("com.squareup.okhttp3:logging-interceptor")

    /* Lifecycle */
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'

    /*Add Coroutine */
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'

    /*Add Coil*/
    implementation 'io.coil-kt:coil:1.3.2'

    /*Add RecyclerView*/
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
}

제 Build.gradle 설정입니다. kapt 사용시 빌드과정에서 문제가 있어 ksp로 변경했고 이후 빌드와 run은 성공적으로 진행하는 것 확인했습니다..

답변 2

0

냉동코더님의 프로필 이미지
냉동코더
지식공유자

KAPT를 사용해도 작동에 문제는 없습니다. JsonAdapter 관련 문제라면 DTO 설정이 제대로 되어있는지 확인해 보세요.

https://github.com/cliearl/book-search-app/blob/Practice02/app/src/main/java/com/qualitybitz/booksearchapp/data/model/Book.kt

build.gradle 설정은 다음 url에서 확인해 보시구요 :)

https://github.com/cliearl/book-search-app/blob/Practice02/app/build.gradle

0

Bruce님의 프로필 이미지
Bruce
질문자

강의 내용대로 build.gradle 설정후 에러는 해결했습니다.
그래도 혹시나 짐작가는 원인이 있다면 알려주시면 감사하겠습니다!

Bruce님의 프로필 이미지

작성한 질문수

질문하기