android - 找不到 'kotlinPlugin' 和 'darkThemeColors'

标签 android android-jetpack android-jetpack-compose

当我尝试使用 jetpack 的 compose 库时,我一直坚持执行 jetpack 文档中提到的步骤(来源:https://developer.android.com/jetpack/compose/setup#compose-compiler)。我无法使用 kotlinPlugin,因为出现以下异常。

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method kotlinPlugin() for arguments [androidx.compose:compose-compiler:0.1.0-dev02] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

此外,我无法使用darkThemeColorslightThemeColors。以下是我添加的 Gradle 依赖项。

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    kotlinPlugin "androidx.compose:compose-compiler:0.1.0-dev02"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.ui:ui-framework:0.1.0-dev02'
    implementation 'androidx.ui:ui-layout:0.1.0-dev02'
    implementation 'androidx.ui:ui-material:0.1.0-dev02'
    implementation 'androidx.ui:ui-tooling:0.1.0-dev02'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.50'
}

我是否缺少任何依赖项?我检查了 MaterialThemeMaterialColors 类,但没有找到 darkThemeColors 和 lightThemeColors。

最佳答案

jetpackCompose示例应用程序 jetnews darkThemeColorslightThemeColorsThemes.kt 中定义下面的文件示例,因此您需要定义颜色。

val lightThemeColors = MaterialColors(
    primary = Color(0xFFDD0D3C),
    primaryVariant = Color(0xFFC20029),
    onPrimary = Color.White,
    secondary = Color.White,
    onSecondary = Color.Black,
    background = Color.White,
    onBackground = Color.Black,
    surface = Color.White,
    onSurface = Color.Black,
    error = Color(0xFFD00036),
    onError = Color.White
)

/**
 * Note: Dark Theme support is not yet available, it will come in 2020. This is just an example of
 * using dark colors.
 */
val darkThemeColors = MaterialColors(
    primary = Color(0xFFEA6D7E),
    primaryVariant = Color(0xFFDD0D3E),
    onPrimary = Color.Black,
    secondary = Color(0xFF121212),
    onSecondary = Color.White,
    surface = Color(0xFF121212),
    background = Color(0xFF121212),
    onBackground = Color.White,
    onSurface = Color.White
) 

在下面的 jetnews 截图中项目 enter image description here 对于 jetnews样本检查此链接 https://developer.android.com/jetpack/compose/setup#sample

关于android - 找不到 'kotlinPlugin' 和 'darkThemeColors',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58551926/

相关文章:

java - ExpandableListView 中奇怪的空指针异常

android - 使用 Room Persistence 库插入一对多关系

android - 添加新基准模块时同步失败

android - 如何安全地(生命周期感知).collectAsState() 一个 StateFlow?

android - 如果不使用 Card 覆盖,Compose Lottie 组件将无法正常工作

javascript - React Native 可以用来构建我的蓝牙应用程序吗?

android - 在 Eclipse 中运行 Android ApiDemos 时出现问题

android - 编写 : beta08 breaks clickable

android - Jetpack compose 如何等待动画结束

android - DEVELOPMENT_SETTINGS 使 Gingerbread 中的应用程序崩溃