ZacSweers / MoshiX

Extensions for Moshi including IR plugins, moshi-sealed, and more.
Apache License 2.0
514 stars 37 forks source link

[R8] No JsonAdapter for interface #530

Closed proninyaroslav closed 9 months ago

proninyaroslav commented 9 months ago

moshi-sealed: 0.24.0 and later moshi: 1.15.0 ksp: 1.9.21-1.0.16

The crash appears on all versions above 0.23.0 with enabled R8:

@JsonClass(generateAdapter = true, generator = "sealed:type")
sealed interface PrefWikiCharactersSort {
    val direction: PrefSortDirection

    @TypeLabel("unknown")
    object Unknown : PrefWikiCharactersSort {
        override val direction: PrefSortDirection
            get() = PrefSortDirection.Unknown
    }

    @TypeLabel("alphabetical")
    @JsonClass(generateAdapter = true)
    data class Alphabetical(
        override val direction: PrefSortDirection
    ) : PrefWikiCharactersSort

    @TypeLabel("date_last_updated")
    @JsonClass(generateAdapter = true)
    data class DateLastUpdated(
        override val direction: PrefSortDirection
    ) : PrefWikiCharactersSort

    @TypeLabel("date_added")
    @JsonClass(generateAdapter = true)
    data class DateAdded(
        override val direction: PrefSortDirection
    ) : PrefWikiCharactersSort
}
java.lang.IllegalArgumentException: No JsonAdapter for interface org.proninyaroslav.opencomicvine.types.preferences.PrefWikiCharactersSort (with no annotations)
    at com.squareup.moshi.Moshi.adapter(SourceFile:29)
    at com.squareup.moshi.Moshi.adapter(SourceFile:2)
    at org.proninyaroslav.opencomicvine.model.AppPreferencesImpl.<init>(SourceFile:41)
    at org.proninyaroslav.opencomicvine.DaggerOpenComicVineApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get(SourceFile:24)
    at dagger.internal.DoubleCheck.get(SourceFile:14)
    at org.proninyaroslav.opencomicvine.DaggerOpenComicVineApplication_HiltComponents_SingletonC$ViewModelCImpl$SwitchingProvider.get(SourceFile:21)
    at androidx.recyclerview.widget.ViewInfoStore.create(SourceFile:618)
    at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(SourceFile:2)
    at androidx.lifecycle.ViewModelProvider.get(SourceFile:11)
    at androidx.lifecycle.ViewModelProvider.get(SourceFile:2)
    at androidx.lifecycle.Lifecycle.viewModel(SourceFile:87)
    at org.proninyaroslav.opencomicvine.ui.MainActivity$onCreate$1.invoke(SourceFile:13)
    at org.proninyaroslav.opencomicvine.ui.MainActivity$onCreate$1.invoke(SourceFile:1)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:8)
    at _COROUTINE._BOUNDARY$$ExternalSyntheticOutline0.m(SourceFile:82)
    at kotlin.TuplesKt.CompositionLocalProvider(SourceFile:178)
    at org.proninyaroslav.opencomicvine.ui.CompositionLocalKt.AppCompositionLocalProvider(SourceFile:57)
    at org.proninyaroslav.opencomicvine.ui.MainActivity$onCreate$1.invoke(SourceFile:37)
    at org.proninyaroslav.opencomicvine.ui.MainActivity$onCreate$1.invoke(SourceFile:2)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:8)
    at androidx.compose.ui.platform.ComposeView.Content(SourceFile:25)
    at androidx.paging.HintHandler$processHint$1.invoke(SourceFile:148)
    at androidx.paging.HintHandler$processHint$1.invoke(SourceFile:38)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:8)
    at _COROUTINE._BOUNDARY$$ExternalSyntheticOutline0.m(SourceFile:82)
    at kotlin.TuplesKt.CompositionLocalProvider(SourceFile:178)
    at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(SourceFile:296)
    at androidx.compose.material.ButtonKt$Button$3.invoke(SourceFile:29)
    at androidx.compose.material.ButtonKt$Button$3.invoke(SourceFile:5)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:8)
    at _COROUTINE._BOUNDARY$$ExternalSyntheticOutline0.m(SourceFile:82)
    at kotlin.TuplesKt.CompositionLocalProvider(SourceFile:178)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(SourceFile:514)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(SourceFile:5)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(SourceFile:1)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:8)
    at _COROUTINE._BOUNDARY$$ExternalSyntheticOutline0.m(SourceFile:82)
    at kotlin.TuplesKt.CompositionLocalProvider(SourceFile:178)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(SourceFile:19)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(SourceFile:2)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:8)
    at androidx.compose.material3.DividerKt.invokeComposable(SourceFile:20)
    at androidx.compose.runtime.ComposerImpl.doCompose(SourceFile:137)
    at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(SourceFile:14)
    at androidx.compose.runtime.CompositionImpl.composeContent(SourceFile:19)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(SourceFile:30)
    at androidx.compose.runtime.CompositionImpl.setContent(SourceFile:11)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(SourceFile:24)
    at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(SourceFile:12)
    at androidx.compose.ui.platform.WrappedComposition.setContent(SourceFile:14)
    at androidx.compose.ui.platform.WrappedComposition.onStateChanged(SourceFile:19)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(SourceFile:23)
    at androidx.lifecycle.LifecycleRegistry.addObserver(SourceFile:216)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(SourceFile:22)
    at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(SourceFile:109)
    at android.view.View.dispatchAttachedToWindow(View.java:21980)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3014)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2465)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9305)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1339)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1348)
    at android.view.Choreographer.doCallbacks(Choreographer.java:952)
    at android.view.Choreographer.doFrame(Choreographer.java:882)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1322)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8177)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
ZacSweers commented 9 months ago

Will need a minimally reproducing project for R8 issues, sorry

proninyaroslav commented 9 months ago

Ok, I'll provide it later.

proninyaroslav commented 9 months ago

Unfortunately I was unable to reproduce this in the minimally reproducing project😅 This is weird. Maybe this is some kind of conflict with other packages, I can only provide their one project in which this problem is observed.

ZacSweers commented 9 months ago

Yeah R8 issues are often usually super specific to the host project. Going to close this for now, feel free to revisit if you can make a public repro.

proninyaroslav commented 9 months ago

@ZacSweers The project is public https://github.com/proninyaroslav/OpenComicVine. I can create a separate branch with version 0.25.1

ZacSweers commented 9 months ago

Can you give me specific build instructions?

proninyaroslav commented 9 months ago

@ZacSweers I created a separate test branch https://github.com/proninyaroslav/OpenComicVine/tree/r8_moshix. I've enabled R8 for a debug build variant, so you can simply build and run the app the normal way (Gradle/Android Studio). Also, the project uses KSP instead of kapt everywhere, if that matters. But when building I get the message: Kapt support in Moshi Kotlin Code Gen is deprecated and will be removed in 2.0. Please migrate to KSP. I don't know the reason.

ZacSweers commented 9 months ago

Please share the exact gradle command.

Re: the warning - this is because hilt loads all processors, we can't do anything about that. There's a bug filed on their side somewhere

proninyaroslav commented 9 months ago
./gradlew installDebug

Also you need OpenJDK 17

ZacSweers commented 9 months ago

Your debug build runs R8 minification?

proninyaroslav commented 9 months ago

I modified the debug version and turned on R8 so that you don’t have to create a release key and so on. There is no difference in both cases.