简体   繁体   English

Jetpack Compose 应用程序无法在 AVD 上启动

[英]Jetpack Compose App doesn't launch on 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.我已经使用Jetpack Compose编写了一个示例,然后每当我尝试InstallInstallAVD ,gradle 都会成功构建Project但构建的应用程序没有启动。 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.关于工具和代码的一切都很好,即使Preview显示UI很好,如果我自己手动构建 APK 并安装它,那么应用程序将正确安装。 in other words Android Studio doesn't install the App on AVD Automatically.换句话说,Android Studio 不会自动在 AVD 上安装该应用程序。

Android Studio = 4.2 Canary 10 | Android Studio = 4.2 Canary 10 | compose = 1.0.0-alpha02 | compose = 1.0.0-alpha02 | kotlin = 1.4.0 | kotlin = 1.4.0 | gradle plugin = 4.2.0-alpha10 | gradle plugin = 4.2.0-alpha10 | gradle = 6.6.1 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.如果您看不到此图标,请一直向右滚动预览窗格。

在设备或模拟器上运行应用程序的预览按钮的屏幕截图

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.但是,要使用 android studio 上的正常运行按钮运行您的应用程序,您需要确保 onCreate 中的 setContent{} 块正在调用您之前声明的可组合函数。 This was the missing link for me as well.这对我来说也是缺失的环节。

确保AndroidManifest 中启动活动的android:exported标志设置为true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM