You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android项目构建失败:com.android.support:support-annotations依赖版本冲突

Fixing the 'support-annotations' Version Conflict in Android Studio 3.0.1

Hey there! I’ve dealt with this exact dependency conflict plenty of times, so let’s get your build back on track.

What’s Causing the Error?

The issue is straightforward: your main app module is using com.android.support:support-annotations:26.1.0, but your Android Test module is pulling in version 27.1.1. Gradle can’t automatically resolve this mismatch, hence the build failure.

Here Are 3 Reliable Fixes:

1. Force All Modules to Use the Same Annotation Version

If you don’t want to update your main app’s support library version right now, you can force Gradle to use the 26.1.0 version across all modules. Add this block to your app-level build.gradle file:

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
}

2. Upgrade Your Main App’s Support Library Version

If you’re open to updating your app to use the newer support library (27.1.1), make these changes to your app-level build.gradle:

  • First, update your compile and target SDK versions to match:
    android {
        compileSdkVersion 27
        defaultConfig {
            targetSdkVersion 27
            // Keep your other default config settings here
        }
    }
    
  • Then, update all your com.android.support dependencies to 27.1.1:
    dependencies {
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:support-annotations:27.1.1'
        // Update any other support library dependencies (like recyclerview, design, etc.) to 27.1.1
    }
    

3. Exclude Conflicting Annotations from Test Dependencies

You can explicitly exclude the support-annotations from your test dependencies, then manually add the version your main app uses. Update your test dependencies block like this:

dependencies {
    // Exclude annotations from test runner and espresso
    androidTestImplementation('com.android.support.test:runner:1.0.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    // Add the matching version for your app
    androidTestImplementation 'com.android.support:support-annotations:26.1.0'
}

Final Step

After making any of these changes, click the Sync Now button in Android Studio to apply the Gradle updates, then try rebuilding your project.

内容的提问来源于stack exchange,提问作者vaibhav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:39:09