首页 > 解决方案 > 新材质依赖项不适用于 CoordinatorLayout 预览

问题描述

因此,我添加了所有 android 新材料依赖以使用 BottomAppBar ,但是在我全部导入并更改了文档建议的内容之后,我什至看不到预览,并且当我编译时,我得到了test.runner不存在的错误,就是这样也许我删除了,support.test.runner因为它说我们不需要将支持与材料混合。

这就是我所做的

我的依赖

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    testImplementation 'junit:junit:4.12'
    implementation "androidx.room:room-runtime:2.1.0-alpha01"
    annotationProcessor "androidx.room:room-compiler:2.1.0-alpha01"

}

风格

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

我在我的 AndroidManifest 应用程序标记中添加了编译器建议的这两行

 tools:replace="android:appComponentFactory"
        android:appComponentFactory="settings"

我更改了AppCompat所有课程中的所有内容,并用新的 AndroidX 替换它们AppCompat

错误

错误:包 android.support.test 不存在

这可能是因为我从我的 gradle 中删除了 support.test,因为在文档中说我们不需要将支持与材料混合。

这个错误试图预览coordinatorLayout

在此处输入图像描述

任何线索可能是什么以及如何解决所有这些问题,因为我需要尽快使用这种材料设计。

另一件事,因为它有 AppCompat,我可以在我的 android 7 上运行并看到这个设计?

谢谢

标签: javaandroidandroid-layout

解决方案


你有什么版本的安卓工作室?根据这里:https ://developer.android.com/jetpack/androidx/migrate Android studio 必须是 3.2 或更高版本。如果您的 android studio 现在是 3.2 或更高版本,则在 Refactor 选项卡下有一个选项-“迁移到 AndroidX”等待它编译所有内容,AS 会将您现有的项目迁移到 androidX,这是您正在寻找的材料。

如果你可能会问,这是我对 androidx 的依赖:

implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

推荐阅读