https://kotlinlang.org logo
#compose
Title
# compose
j

Joshua McWilliams

07/13/2020, 2:25 PM
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 ‘appkaptDebugKotlin’.
> 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:
Copy 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())
    }
}
a

Adam Powell

07/13/2020, 7:55 PM
I think he's in this slack, @cb maybe he can explain what he did here 🙂
c

cb

07/13/2020, 7:56 PM
It's because the Kotlin compiler used in Compose doesn't play well with
lateinit
a

Adam Powell

07/13/2020, 7:58 PM
we're hoping to have a compiler update Real Soon Now™️ so hopefully any workarounds will not be long-lived at this point
👍 6