【问题标题】:Why CoordinatorLayout not found on my project为什么在我的项目中找不到 CoordinatorLayout
【发布时间】:2018-10-15 14:55:25
【问题描述】:

在这里发布之前,我搜索了很多,但找不到解决方案。

为什么在我的项目中找不到 CoordinatorLayout?

截图

分级

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.salah250.forvo"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //Material Design
    implementation 'com.android.support:design:27.1.1'
    //Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    //GSON
    implementation 'com.google.code.gson:gson:2.8.5'
    //Event Bus
    implementation 'org.greenrobot:eventbus:3.1.1'
    //Picasso
    implementation 'com.squareup.picasso:picasso:2.71828'
    //Butter knife
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    //Circle Image
    implementation 'de.hdodenhof:circleimageview:2.2.0'
}

我希望找到解决这个问题的方法......................................

【问题讨论】:

    标签: android android-studio android-gradle-plugin android-coordinatorlayout


    【解决方案1】:

    如果您检查了依赖项 (com.android.support:appcompat-v7:27.1.1) 并且在以 androidx.coordinatorlayout 开头的布局中,这意味着 您仍在使用支持库依赖项,但您正在尝试使用AndroidX CoordinatorLayout

    使用来自RefactorMigrate to AndroidX,或者使用支持库CoordinatorLayout

    <android.support.design.widget.CoordinatorLayout>
    </android.support.design.widget.CoordinatorLayout>
    

    阅读: https://developer.android.com/jetpack/androidx/migrate

    【讨论】:

      【解决方案2】:

      设置 AndroidX 有一些先决条件。您可以在文档的Using AndroidX 部分以及Migrate an existing project using Android Studio 中找到其中的一些。

      从您提供的 sn-p 中我能注意到的第一件事也是唯一的事情,您没有将 compileSdkVersion 设置为 28,但请检查我提供给您的链接。可能还有更多。

      【讨论】:

      • compileSdkVersion 是 28 但我改成 27 因为不工作
      • 尝试在您的 gradle 文件中添加 compileSdkVersion 28,在您的 gradle.properties 文件中添加 android.useAndroidX=true android.enableJetifier=true。如果这不起作用,请参阅文档了解更多信息。
      • @NiravKotecha 乐于提供帮助 :)
      【解决方案3】:

      只需将这两行放在你的 gradle.properties -file 中:

      android.useAndroidX=true
      android.enableJetifier=true
      

      做一个 gradle 同步,你就设置好了 :)

      【讨论】:

      • 在什么里面?
      • 您的项目文件夹中有一个名为 gradle.properties 的文件。您必须在此处添加提到的行,进行 gradle 同步,然后您应该找到带有 androidX 的 CoordinatorLayout
      猜你喜欢
      • 2022-01-03
      • 1970-01-01
      • 2019-05-21
      • 2019-09-17
      • 2012-08-11
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      相关资源
      最近更新 更多