无法访问 ActivityCompatApi23 class 未找到 ActivityCompatApi23 文件

cannot access ActivityCompatApi23 class file for ActivityCompatApi23 not found

你好,我在我的项目中添加了一个信号库,当我 运行 项目时,我的代码中出现了很多错误,最上面的是

Error:(66, 8) error: cannot access ActivityCompatApi23
class file for android.support.v4.app.ActivityCompatApi23 not found

这是我的家属

    compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:26.0.0-alpha1'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'

compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.github.lzyzsd:circleprogress:1.1.0@aar'
compile 'com.github.clans:fab:1.6.2'
compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
compile 'se.emilsjolander:stickylistheaders:2.1.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.makeramen:roundedimageview:2.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'org.hashids:hashids:1.0.1'
compile 'com.google.android.gms:play-services-analytics:10.2.1'
compile 'com.google.android.gms:play-services-drive:10.2.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'

compile 'com.onesignal:OneSignal:3.+@aar'
compile 'com.google.android.gms:play-services-gcm:10.2.1'
compile "com.google.android.gms:play-services-location:10.2.1"

compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'

compile 'com.google.android.gms:play-services-analytics:10.2.1'
compile 'com.adjust.sdk:adjust-android:4.12.0'
compile 'com.android.installreferrer:installreferrer:1.0'

您正在使用不同版本的支持库

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:26.0.0-alpha1' <- here you are compiling 26.0.0-alpha1
// ...
compile 'com.android.support:appcompat-v7:26.+'
// ...

compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.+' <- this one can be different from 26.0.0-alpha1 since it compiles versions greater than 26, i.e. version 27.1.1
compile 'com.android.support:design:26.+'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.android.support:cardview-v7:26.+'
// ...

因此,当 gradle 尝试构建您的项目时,它会发现两个不同的支持库版本。

我想您可以通过将所有支持库升级到版本 27.1.1 来解决您的问题。像这样

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:27.1.1'
// ...
compile 'com.android.support:appcompat-v27.1.1'
// ..
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:recyclerview-v7:27.1.1'
compile 'com.android.support:cardview-v7:27.1.1'
// ...

此外,正如 parekhkruti26 在评论中所说,永远不要对版本使用 'X.+',因为它可能会导致这样的问题,因此不推荐使用。我猜 android studio 在使用 'X.+'.

添加依赖项时本身会显示警告