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

Android Studio 3.0.1依赖冲突求助:preDebugAndroidTestBuild任务执行失败

Fixing Support Annotations Version Conflict in Android Studio 3.0.1

Hey there, let's tackle this dependency conflict you're running into. The error spells it out clearly: your main app module is using com.android.support:support-annotations:26.1.0, but your test module is pulling in version 27.1.1. Mismatched support library versions like this break builds because they can cause runtime inconsistencies, so Android Studio flags it to prevent headaches later.

Here are two solid ways to fix this:

Method 1: Force a Unified Version Globally

This is the quickest fix—we’ll tell Gradle to use the same annotations version across your entire project, including the test module.

Open your app module’s build.gradle (not the root project one) and add this inside the android block:

android {
    // Keep your existing android configurations here (compileSdkVersion, defaultConfig, etc.)

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

This forces every dependency in your project (even hidden transitive ones from test libraries) to use version 26.1.0 of the annotations, wiping out the conflict entirely.

Method 2: Exclude Conflicting Dependencies in Test Config

If you’d rather not force versions globally, you can explicitly exclude the conflicting annotations from your test dependencies and manually add the correct version.

In your app module’s build.gradle, update your dependencies block like this:

dependencies {
    // Your main app dependencies (keep these as is)
    implementation 'com.android.support:support-annotations:26.1.0'

    // Update test dependencies to exclude conflicting annotations
    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 annotations version to your test dependencies
    androidTestImplementation 'com.android.support:support-annotations:26.1.0'
}

Final Steps

After making either change:

  • Click the Sync Now button in Android Studio to apply the Gradle updates.
  • Clean and rebuild your project (go to Build > Clean Project, then Build > Rebuild Project).

That should resolve the preDebugAndroidTestBuild failure caused by the version mismatch.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:30:16