You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio Flamingo/Giraffe中找不到Empty Compose Activity模板求助

解决Empty Compose Activity模板不显示的问题
  • 检查Jetpack Compose插件状态
    打开Settings(Windows/Linux:File > Settings;Mac:Android Studio > Settings),进入Plugins,搜索Jetpack Compose,确保插件已启用且是最新版本。未安装则点击安装后重启Android Studio。

  • 确认项目创建配置
    创建新项目时,Minimum SDK需选择API 21及以上版本,Language必须选Kotlin——这两个是Compose模板加载的基础要求。

  • 清理Android Studio缓存
    点击File > Invalidate Caches...,选择Invalidate and Restart,等待Studio重启并重建缓存,多数模板加载异常都能通过这个操作解决。

  • 手动搭建Empty Compose Activity
    如果以上方法无效,可手动构建项目结构:

    1. 创建普通的Empty Activity项目(选择Kotlin语言)
    2. 在模块级build.gradle中添加Compose依赖:
      dependencies {
          implementation platform('androidx.compose:compose-bom:2023.06.01')
          implementation 'androidx.compose.ui:ui'
          implementation 'androidx.compose.ui:ui-graphics'
          implementation 'androidx.compose.ui:ui-tooling-preview'
          implementation 'androidx.compose.material3:material3'
          debugImplementation 'androidx.compose.ui:ui-tooling'
          debugImplementation 'androidx.compose.ui:ui-test-manifest'
      }
      
    3. 在build.gradle的android块中启用Compose:
      android {
          buildFeatures {
              compose true
          }
          composeOptions {
              kotlinCompilerExtensionVersion '1.4.7'
          }
      }
      
    4. 将默认Activity代码替换为Compose实现:
      class MainActivity : ComponentActivity() {
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContent {
                  MyApplicationTheme {
                      Surface(
                          modifier = Modifier.fillMaxSize(),
                          color = MaterialTheme.colorScheme.background
                      ) {
                          Greeting("Android")
                      }
                  }
              }
          }
      }
      
      @Composable
      fun Greeting(name: String, modifier: Modifier = Modifier) {
          Text(
              text = "Hello $name!",
              modifier = modifier
          )
      }
      
      @Preview(showBackground = true)
      @Composable
      fun GreetingPreview() {
          MyApplicationTheme {
              Greeting("Android")
          }
      }
      
    5. 同步项目后即可运行。

内容的提问来源于stack exchange,提问作者Edenilson Ferreira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 17:02:01