Open Candice-Gunter opened 2 months ago
Also experiencing this problem. It is noteworthy that, slightly earlier in the "Update the text" section in the prior screen (URL below), some of the text automatically generated by Android Studio is slightly different than shown in the course. https://developer.android.com/codelabs/basic-android-kotlin-compose-first-app?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-1-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-first-app#3 On lines 18 - 33 of MainActivity.kt, Android Studio autogenerates the following:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
GreetingCardTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
}
}
}
}
}
Whereas the tutorial shows that the text below should be generated by default:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
GreetingCardTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}
}
}
}
For anyone who might be struggling to get past this section, I have found that I am able to continue to progress past this initial step by going through the "Update the text" and "Change the background color" sections of the course, and replaced all Android Studio auto-generated text with text in MainActivity.kt presented by the tutorial, and seem to have no issues getting to the end of the "Create your first android app" section. Alternatively, you can skip to "Review the solution code" and copy that into Android Studio, and simply refer to that.
It is vitally important for new and beginner Android developers, such as ourselves, that even minor differences such as this are addressed in introductory material, as we do not yet have the skills and familiarity with the tools in front of us to easily troubleshoot issues. I sincerely hope that there aren't too many issues similar to this moving forward with this otherwise fantastic course.
URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-compose-first-app?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-1-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-first-app#4
In which task and step of the codelab can this issue be found? Towards the end when adding the Surface container.
Describe the problem An error on Text appears which reads "@Composable invocations can only happen from the context of a @Composable function".
Steps to reproduce?
Versions _Android Studio version: Android Studio Koala 2024.1.1
Additional information