【问题标题】:How to fix "Missing classes" error in Android Studio? [duplicate]如何修复 Android Studio 中的“Missing classes”错误? [复制]
【发布时间】:2019-08-15 14:15:09
【问题描述】:

当我尝试在 Android Studio 中进行新活动时 这些错误发生了,在此错误之前我通常创建了一些活动(没有任何错误):

The following classes could not be found:
- android.support.constraint.ConstraintLayout (    Add constraint-layout library dependency to the project, Fix Build Path, Edit XML, Create Class)
- android.support.design.widget.CoordinatorLayout (Fix Build Path, Edit XML, Create Class)
- android.support.v7.widget.Toolbar (Fix Build Path, Edit XML, Create Class)

依赖库:


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.android.support:support-v4:29.+'
    implementation 'com.android.support:design:29.+'
    implementation 'com.android.support:appcompat-v7:29.+'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.0.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
    implementation 'com.google.android.gms:play-services-base:11.0.1'
    implementation 'com.google.android.gms:play-services-basement:11.0.1'
    implementation 'com.google.android.gms:play-services-safetynet:11.0.1'
    implementation 'com.google.android.gms:play-services-tasks:11.0.1'
}

【问题讨论】:

  • 在这里发布你的依赖库代码。
  • 编辑了第一篇文章
  • 你有AndroidX项目,你说你创建的活动没有任何错误,所以检查这些活动:android.support.constraint.ConstraintLayout,android.support.design.widget.CoordinatorLayout, android.support.v7.widget.Toolbar ...并将其转换为androidx依赖。

标签: java android xml


【解决方案1】:

看起来您正尝试在同一个项目中使用 AndroidX 库和支持库。从菜单迁移到 AndroidX,它将替换包名和依赖项。

您的项目正在添加来自支持库而不是 AndroidX 的小部件,这会导致此问题。

如果您仍然遇到错误,请从列表中替换旧包名称: https://developer.android.com/jetpack/androidx/migrate

【讨论】:

  • @Niklaus 转到您的laylut 文件并将约束布局的包名称替换为androidx.widget.constraintLayout
【解决方案2】:

您将AndroidX 依赖项与AppCompat 混淆了。将其从 Refactor 迁移到 AndroidX -> 迁移到 AndroidX 或使用 AppCompat。

就像在您的代码中一样,您已经使用了Constraint Layout 的两个依赖项。解决您的问题的最简单方法是删除该行

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 2020-12-14
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    相关资源
    最近更新 更多