'ComponentActivity can only be called from within the same library group prefix

I have a working simple Android app with MainActivity of AppCompatActivity. I changed to ComponentActivity and it generates the following warning.

ComponentActivity can only be called from within the same library group prefix (referenced groupId=androidx.core with prefix androidx from groupId=Compose play)

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            MessageCard(Message("Hello", "J C"))
        }
    }
}

But the app still compiles and runs normally. Is there any way to resolve this other than @SuppressLint("RestrictedApi")? Thanks



Solution 1:[1]

You've imported the wrong ComponentActivity. Make sure you are importing androidx.activity.ComponentActivity

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ianhanniballake