我似乎在compose中使用Preview遇到了问题,当我用@preview注释compose方法时,布局面板不会出现。我假设我遗漏了一个依赖项,但我已经从这里复制并粘贴了https://developer.android.com/jetpack/compose/setup的代码。有什么建议吗?(尝试了通常的清除缓存、重新打开项目等) :)
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.0-alpha10'
kotlinCompilerVersion '1.4.21'
}
}
dependencies {
implementation 'androidx.compose.ui:ui:1.0.0-alpha10'
// Tooling support (Previews, etc.)
implementation 'androidx.compose.ui:ui-tooling:1.0.0-alpha10'
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation 'androidx.compose.foundation:foundation:1.0.0-alpha10'
// Material Design
implementation 'androidx.compose.material:material:1.0.0-alpha10'
// Material design icons
implementation 'androidx.compose.material:material-icons-core:1.0.0-alpha10'
implementation 'androidx.compose.material:material-icons-extended:1.0.0-alpha10'
// Integration with observables
implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-alpha10'
implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha10'
// UI Tests
androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.0.0-alpha10'
implementation 'com.google.android.material:material:1.2.1'
}
这是我使用预览的尝试(正如它所说的,函数"DefaultPreview“从未使用过)
import androidx.compose.ui.tooling.preview.Preview
.....
@Preview
@Composable
fun DefaultPreview() {
Text(text = "Hello!")
}
发布于 2021-11-12 11:51:38
buildFeatures {
compose true
}
在build.gradle文件中的Android块中编写上述代码。这样你的问题就解决了。
发布于 2021-01-22 10:18:39
我将把这个留下来,以防其他人遇到和我一样的问题(这是用户错误,但我也认为文档可以更清楚)。
有两个版本的安卓金丝雀,测试版和北极狐(alpha)。如果你想使用最新版本的compose库,请确保你使用的是北极狐。我发现compose库'androidx.compose.ui:ui-tooling:1.0.0-alpha08'
(以及更高版本)在测试版的canary上不能很好地工作。
发布于 2021-06-29 16:50:35
我认为你可以在配置中找到你想要的东西
https://stackoverflow.com/questions/65837989
复制相似问题