Jetpack Compose в шаблоне Basic Activity

Рейтинг: 0Ответов: 0Опубликовано: 01.08.2023

Не могу подключить Compose к Basic Activity. В build.gradle прописаны зависимости (взято отсюда https://developer.android.com/jetpack/compose/setup

android    
{
    ...
     kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.8"
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
//    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

//    val composeBom = platform("androidx.compose:compose-bom:2023.06.01")
    implementation(platform("androidx.compose:compose-bom:2023.06.01"))
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.06.01"))
    implementation("androidx.compose.material3:material3")
    implementation("androidx.compose.ui:ui-tooling-preview")
    debugImplementation("androidx.compose.ui:ui-tooling")
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-test-manifest")
    implementation("androidx.compose.material:material-icons-core")
}

Файл Main.Activity. В нем НЕ ПОДКЛЮЧАЕТСЯ импорт setContent и Text, они красные. Gradle синхронизирован, среда перезапускалась. Что я делаю не так?

import android.os.Bundle
import androidx.activity.ComponentActivity
//import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.setContent
import org.w3c.dom.Text

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Greeting()
        }
    }
}
@Composable
fun Greeting() {
    Column {
        Text(text = "Hello")
    }
}

Ответы

Ответов пока нет.