facebook / litho

A declarative framework for building efficient UIs on Android.
https://fblitho.com
Apache License 2.0
7.71k stars 763 forks source link

No static field useSharedLayoutStateFuture of type Z in class Lcom/facebook/litho/config/ComponentsConfiguration #652

Closed Junaid-Sakib closed 4 years ago

Junaid-Sakib commented 4 years ago

Version

//Litho implementation 'com.facebook.litho:litho-core:0.34.0' implementation 'com.facebook.litho:litho-widget:0.34.0' kapt 'com.facebook.litho:litho-processor:0.34.0' implementation 'com.facebook.soloader:soloader:0.6.0' implementation 'com.facebook.litho:litho-fresco:0.34.0' testImplementation 'com.facebook.litho:litho-testing:0.34.0' implementation 'com.facebook.litho:litho-sections-core:0.34.0' implementation 'com.facebook.litho:litho-sections-widget:0.23.0' compileOnly 'com.facebook.litho:litho-sections-annotations:0.23.0' annotationProcessor 'com.facebook.litho:litho-sections-processor:0.23.0'

Issues and Steps to Reproduce


Exception: 
  Process: com.c.s.debug, PID: 10470
    com.facebook.litho.ComponentsChainException: NpsGroupSection
    Caused by: java.lang.NoSuchFieldError: No static field useSharedLayoutStateFuture of type Z in class Lcom/facebook/litho/config/ComponentsConfiguration; or its superclasses (declaration of 'com.facebook.litho.config.ComponentsConfiguration' appears in /data/app/com.c.s.selfcare.debug-Dzqb31m_W6OeIHJ-YOIcPw==/base.apk)
        at com.facebook.litho.sections.widget.RecyclerBinderConfiguration$Builder.<init>(RecyclerBinderConfiguration.java:203)
        at com.facebook.litho.sections.widget.RecyclerBinderConfiguration.create(RecyclerBinderConfiguration.java:49)
        at com.facebook.litho.sections.widget.ListRecyclerConfiguration$Builder.<clinit>(ListRecyclerConfiguration.java:165)
        at com.facebook.litho.sections.widget.ListRecyclerConfiguration.<init>(ListRecyclerConfiguration.java:84)
        at com.facebook.litho.sections.widget.ListRecyclerConfiguration.<init>(ListRecyclerConfiguration.java:72)
        at com.facebook.litho.sections.widget.RecyclerCollectionComponentSpec.<clinit>(RecyclerCollectionComponentSpec.java:93)
        at com.facebook.litho.sections.widget.RecyclerCollectionComponent.<init>(RecyclerCollectionComponent.java:100)
        at com.facebook.litho.sections.widget.RecyclerCollectionComponent.create(RecyclerCollectionComponent.java:719)
        at com.facebook.litho.sections.widget.RecyclerCollectionComponent.create(RecyclerCollectionComponent.java:714)
        at com.c.s.v2.nps.view.litholayout.spec.NpsGroupSectionSpec.onCreateLayout(NpsGroupSectionSpec.kt:42)
        at com.c.s.v2.nps.view.litholayout.spec.NpsGroupSection.onCreateLayout(NpsGroupSection.java:44)
        at com.facebook.litho.ComponentLifecycle.createComponentLayout(ComponentLifecycle.java:168)
        at com.facebook.litho.Layout.onCreateLayout(Layout.java:361)
        at com.facebook.litho.Layout.create(Layout.java:181)
        at com.facebook.litho.Layout.create(Layout.java:119)
        at com.facebook.litho.Layout.createAndMeasureComponent(Layout.java:76)
        at com.facebook.litho.LayoutState.calculate(LayoutState.java:1444)
        at com.facebook.litho.ComponentTree$LayoutStateFuture.calculateLayoutStateInternal(ComponentTree.java:2456)
        at com.facebook.litho.ComponentTree$LayoutStateFuture.access$2700(ComponentTree.java:2374)
        at com.facebook.litho.ComponentTree$LayoutStateFuture$1.call(ComponentTree.java:2434)
        at com.facebook.litho.ComponentTree$LayoutStateFuture$1.call(ComponentTree.java:2426)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at com.facebook.litho.ComponentTree$LayoutStateFuture.runAndGet(ComponentTree.java:2545)
        at com.facebook.litho.ComponentTree.calculateLayoutState(ComponentTree.java:2339)
        at com.facebook.litho.ComponentTree.measure(ComponentTree.java:1061)
        at com.facebook.litho.LithoView.onMeasure(LithoView.java:354)
        at android.view.View.measure(View.java:23169)
        at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
        at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
2020-04-22 13:29:27.352 10470-10470/com.c.s.debug E/AndroidRuntime:     at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at com.android.internal.policy.DecorView.onMeasure(DecorView.java:716)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2718)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1572)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1855)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
        at android.view.Choreographer.doFrame(Choreographer.java:696)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Expected Behavior

*Should not crash, the example I followed is at: https://www.codota.com/web/assistant/code/rs/5c7cb4522ef5570001df7644#L34 which comes from a fb class

Link to Code

@LayoutSpec
object GroupSectionSpec {
    @OnCreateLayout
    fun onCreateLayout(
        c: ComponentContext,
        @Prop model: List<ISurveyComponent>
    ): Component? {
        return RecyclerCollectionComponent.create(c)
            .section(
                DataDiffSection.create<ISurveyComponent>(SectionContext(c))
                    .data(model)
                    .renderEventHandler(NpsGroupSection.onRender(c))
                   // .onCheckIsSameItemEventHandler(NpsGroupSection.isSameItem(c))
                    .build()
            )
            .canMeasureRecycler(true)
            .disablePTR(true)
            .build()
    }

    @OnEvent(RenderEvent::class)
    fun onRender(c: ComponentContext, @FromEvent model: ISurveyComponent): RenderInfo {
        val lenFilter: InputFilter = InputFilter.LengthFilter(250) // move from here
        val rComponent: Component = when (model.getKind()) {
            CardType.RADIO -> {
                Text.create(c)
                    .alignment(TextAlignment.CENTER)
                    .alignSelf(YogaAlign.CENTER)
                    .widthDip(20F)
                    .text("text")
                    .build()
            }
            CardType.TEXT_AREA -> {
                CirclesTextArea.create(c)
                    .lenFilter(lenFilter)
                    .maxLines(10)
                    .minLines(6)
                    .textColor(R.color.circlesBlack).build()
            }
            CardType.FOOTER -> {
                Text.create(c)
                    .alignment(TextAlignment.CENTER)
                    .alignSelf(YogaAlign.CENTER)
                    .widthDip(20F)
                    .text("text")
                    .build()
            }
            CardType.HEADER -> {
                Text.create(c)
                    .alignment(TextAlignment.CENTER)
                    .alignSelf(YogaAlign.CENTER)
                    .widthDip(20F)
                    .text("text")
                    .build()
            }
            CardType.UNKNOWN -> {
                Text.create(c)
                    .alignment(TextAlignment.CENTER)
                    .alignSelf(YogaAlign.CENTER)
                    .widthDip(20F)
                    .text("Cannot Render")
                    .build()
            }
        }

        return ComponentRenderInfo.create().component(rComponent).build()
    }

    @OnEvent(OnCheckIsSameItemEvent::class)
    fun isSameItem(
        c: ComponentContext?,
        @FromEvent previousItem: ISurveyComponent,
        @FromEvent nextItem: ISurveyComponent
    ): Boolean {
        return previousItem.getKind() === nextItem.getKind()
    }
}

colriot commented 4 years ago

@Junaid-Sakib You have two different versions of libs used across your Gradle config: 0.34.0 and 0.23.0. Please, put the latest version for all the Litho artifacts 0.34.0 and check it out again.

Junaid-Sakib commented 4 years ago

Thanks @colriot that helps! Not sure where I got the mismatching versions from!

colriot commented 4 years ago

Also, if make sure to use either kapt or annotationProcessor config for processor deps, depending on whether you use Litho from Kotlin or not. Now you have both in you config

Junaid-Sakib commented 4 years ago

Thanks a lot for pointing that out, much appreciated :)