错误:(59,8)错误:无法访问未找到android.support.v4.app.ActivityCompatApi23的ActivityCompatApi23类文件

这是我的build.gradle

apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "26.0.2" android { configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' } } defaultConfig { applicationId "com.example.user2.trafficmap" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } repositories { mavenCentral() maven { url "https://maven.google.com" } } dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'io.nlopez.smartlocation:library:3.3.3' compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.google.android.gms:play-services-location:11.8.0' compile 'com.google.android.gms:play-services-base:11.8.0' compile 'com.google.android.gms:play-services-maps:11.8.0' compile 'com.github.arimorty:floatingsearchview:2.1.1' compile 'com.google.android.gms:play-services-places:11.4.2' testCompile 'junit:junit:4.12' compile 'com.android.support:recyclerview-v7:26.0.0' } 

当我运行我的项目时,我看到了这个错误

错误:(59,8)错误:无法访问未找到android.support.v4.app.ActivityCompatApi23的ActivityCompatApi23类文件

错误:任务’:app:compileDebugJavaWithJavac’的执行失败。

编译失败; 请参阅编译器错误输出以获取详细信

我该如何解决这个问题? 🙁

我通过在build.gradle中添加此代码解决了这个问题

 configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' } } } } 

所有support库都需要是相同的版本。 如果您的编译SDK是25,那么它是25.3.0。 如果您的编译SDK是26,那么它是26.0.0。 不要混合它们

这应该可以解决你的问题

  compile 'com.android.support:appcompat-v7:25.3.0' compile 'com.android.support:recyclerview-v7:25.3.0' 

我只是换了线

compile 'com.android.support:appcompat-v7:26.0.0-alpha1'

 compile 'com.android.support:appcompat-v7:26.+'