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

Android App Gradle依赖问题:com.android.support.test:runner:1.0.2异常

Fixing Gradle Dependency Issues with androidTestImplementation 'com.android.support.test:runner:1.0.2' and AppCompat

Hey there, let's work through this Gradle dependency problem you're hitting. From what you described, removing the test runner dependency breaks your AppCompat configuration—here's why that's happening and how to fix it:

Why This Happens

The com.android.support.test:runner dependency doesn't exist in isolation; it often pulls in shared support library components that your AppCompat dependency relies on. When you yank it out, Gradle can't resolve those shared components anymore, leading to the red error on your AppCompat line. Also, Android Support Library dependencies must all use the same version—mismatched versions between test libraries and main app libraries are a common source of these conflicts.

Step-by-Step Solutions

1. Don't Remove the Test Runner—Fix the Conflict Instead

The test runner is essential for running instrumented tests, so removing it isn't the right fix. Instead, resolve the version mismatch:

  • First, check that your AppCompat version matches the support library version expected by the test runner. For runner:1.0.2, the corresponding support library version is 28.0.0 (since this is the last version of the old Support Library before AndroidX).
  • Update your AppCompat dependency to match:
    implementation 'com.android.support:appcompat-v7:28.0.0'
    

2. Force Unified Support Library Versions

If you still see conflicts, force all support library dependencies to use the same version. Add this to your module-level build.gradle file:

configurations.all {
    resolutionStrategy.force 'com.android.support:appcompat-v7:28.0.0'
    resolutionStrategy.force 'com.android.support:support-core-utils:28.0.0'
    // Add other support library modules here if needed
}

This ensures Gradle uses the exact version you specify for all support library components, eliminating version clashes.

3. Migrate to AndroidX (Long-Term Fix)

The old Android Support Library is deprecated, so migrating to AndroidX will prevent these kinds of issues in the future. Here's how:

  1. Open your gradle.properties file and add these lines:
    android.useAndroidX=true
    android.enableJetifier=true
    
  2. Replace your old Support Library dependencies with AndroidX equivalents:
    • Replace com.android.support:appcompat-v7:28.0.0 with androidx.appcompat:appcompat:1.6.1
    • Replace com.android.support.test:runner:1.0.2 with androidx.test:runner:1.5.2
  3. Sync your Gradle project—Jetifier will automatically adjust any remaining third-party dependencies to use AndroidX.

4. Verify Dependency Tree

To dig deeper into what's causing the conflict, run this command in your project root to generate a full dependency tree:

# For macOS/Linux
./gradlew app:dependencies

# For Windows
gradlew.bat app:dependencies

Look for lines where AppCompat or support library components have conflicting versions—this will help you pinpoint exactly which dependencies need adjustment.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:13:36