Cannot access 'setContent': it is internal in 'androidx.compose.ui.platform'

Viewed 3461

I'm using

  • Android Studio 4.3 (Artix Fox | 2020.3.1 Canary 5),
  • compose_version = '1.0.0-beta01'
  • Kotlin version 1.4.30

When I open Empty Compose Activity and compile, I got the below error

e: MainActivity.kt: (9, 37): Cannot access 'setContent': it is internal in 'androidx.compose.ui.platform'

It's so strange as it is a template-generated project, and should work. Any workaround it?

4 Answers

Add this line in your gradle

// In charge of setContent
implementation "androidx.activity:activity-compose:1.0.0-beta01"

https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0-beta01

ComponentActivity.setContent() was removed from compose:ui. Use the one from androidx.activity:activity-compose. viewModel() and LocalViewModelStoreOwner were removed from compose:ui. Use the ones from androidx.lifecycle:lifecycle-viewmodel-compose.

Have you added androidx.activity:activity-compose:1.3.0-alpha03 to your dependencies? If you haven't, you should do. If you have, re-import the correct androidx.activity.compose.setContent.

By the way, Jetpack Compose is changing fast during its alpha stage so it is not strange that templates of old Android Studio versions are out of date. You'd better keep using the latest Android Studio version if you want to use Jetpack Compose.

Agree, after changing to Android Studio 4.3 (Artix Fox | 2020.3.1 Canary 8) all works. It is now import androidx.activity.compose.setContent instead of from androidx.compose.ui.platform.setContent. All works now.

Now setContent is part of activity compose not UI. Add below dependency : implementation "androidx.activity:activity-compose:1.3.0-alpha03"

It resides inside below package. import androidx.activity.compose.setContent

I face same issue and this solved the issue. Happy coding.

Related