Thread
#compose
    j

    Joshua McWilliams

    2 years ago
    I am attempting to migrate an existing fragment in MVVM to use compose to render the view, we are currently injecting the viewModel into the Fragment via Dagger, anytime I build I get the following Kapt Exception:
    Execution failed for task ‘:app:kaptDebugKotlin’.
    A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
       > java.lang.reflect.InvocationTargetException (no error message)
    Any ideas how to get Dagger to place nice with Compose? Fragment Code:
    class HomeFragment : Fragment() {
    
       @Inject
       lateinit var viewModelFactory: ViewModelFactory
       private val vm: HomeViewModel by viewModels { viewModelFactory }
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            AndroidSupportInjection.inject(this)
        }
    
        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            val fragmentView = inflater.inflate(R.layout.compose_container, container, false)
    
            (fragmentView as ViewGroup).setContent {
                LetsComposeTheme {
                    HomeTabContent()
                }
            }
            return fragmentView
        }
    }
    
    @Composable
    fun HomeTabContent() {
        VerticalScroller {
              drawSectionCard(createSections())
        }
    }
    c

    chris

    2 years ago
    I've seen something similar to this work for Chris Banes:https://github.com/chrisbanes/tivi/blob/main/ui-episodedetails/src/main/java/app/tivi/episodedetails/EpisodeDetailsFragment.kt Does anyone else know how he got this to work and why it does for him but not for @Joshua McWilliams? What's the difference?
    Adam Powell

    Adam Powell

    2 years ago
    I think he's in this slack, @cb maybe he can explain what he did here 🙂
    cb

    cb

    2 years ago
    It's because the Kotlin compiler used in Compose doesn't play well with
    lateinit
    Adam Powell

    Adam Powell

    2 years ago
    we're hoping to have a compiler update Real Soon Now™️ so hopefully any workarounds will not be long-lived at this point