Jetpack Compose 应用程序无法在 AVD 上启动 [英] Jetpack Compose App doesn't launch on AVD

查看:40
本文介绍了Jetpack Compose 应用程序无法在 AVD 上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Jetpack Compose 编写了一个示例,然后每当我尝试在 AVDInstall 它时,gradle 都会构建 项目 成功,但内置应用程序未启动.关于工具和代码的一切都很好,即使 Preview 显示 UI 也很好,如果我自己手动构建 APK 并安装它,那么应用程序将正确安装.换句话说,Android Studio 不会自动在 AVD 上安装该应用程序.

I've written a sample using Jetpack Compose then whenever i try to Install it on an AVD, gradle builds the Project Successfully but the Built App doesn't launch. Everything About the Tools and Codes is ok, even Preview shows UI fine, if i Build APK and Install it myself manually then the app will install and correctly. in other words Android Studio doesn't install the App on AVD Automatically.

Android Studio = 4.2 Canary 10 |compose = 1.0.0-alpha02 |kotlin = 1.4.0 |gradle 插件 = 4.2.0-alpha10 |gradle = 6.6.1

Android Studio = 4.2 Canary 10 | compose = 1.0.0-alpha02 | kotlin = 1.4.0 | gradle plugin = 4.2.0-alpha10 | gradle = 6.6.1

推荐答案

我遇到了同样的问题,但对我有用的是从预览中运行它.连接设备后,点击预览窗格右上角的小运行图像(带有绿色播放图标)将在设备或模拟器上启动.如果您看不到此图标,请将预览窗格一直滚动到右侧.

I had the same issue, but what worked for me was running it from the preview. Once you have a connected device, hitting the little run image(with a green play icon) on the top right corner of the preview pane will launch on the device or emulator. If you can't see this icon, scroll the preview pane all the way to the right.

但是,要使用 android studio 上的正常运行按钮运行您的应用程序,您需要确保 onCreate 中的 setContent{} 块正在调用您之前声明的可组合函数.这对我来说也是缺失的环节.

However, to run your app using the normal run button on android studio, you need to make sure that your setContent{ } block inside onCreate is calling your Composable functions you declared earlier. This was the missing link for me as well.

这篇关于Jetpack Compose 应用程序无法在 AVD 上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆