Android App Gradle依赖问题:com.android.support.test:runner:1.0.2异常
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:
- Open your
gradle.propertiesfile and add these lines:android.useAndroidX=true android.enableJetifier=true - Replace your old Support Library dependencies with AndroidX equivalents:
- Replace
com.android.support:appcompat-v7:28.0.0withandroidx.appcompat:appcompat:1.6.1 - Replace
com.android.support.test:runner:1.0.2withandroidx.test:runner:1.5.2
- Replace
- 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

