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

依赖项解析错误(Error resolving dependencies):为何依赖被解析至不同API级别?

Fixing Error Resolving Dependencies with Mismatched API Levels in Android

Hey there! I totally get how frustrating this dependency resolution error is when you're new to Android dev—especially when you thought you matched your appcompat version to your compileSdkVersion. Let's walk through practical fixes to get this sorted:

Common Fixes to Try

  • Double-check ALL dependencies for API level alignment
    It's not just appcompat that can cause this! Other dependencies like material, constraintlayout, or core-ktx might be pulling in versions that don't match your compileSdkVersion. Open your module-level build.gradle (the one inside your app folder) and verify every implementation line. For example, if your compileSdkVersion 34, stick to appcompat versions like 1.6.1 (which targets API 34), and material versions like 1.11.0.

  • Force consistent dependency versions
    Sometimes indirect dependencies (libraries your main dependencies rely on) can sneak in conflicting versions. You can force Gradle to use a specific version for problematic libraries by adding this block to your module-level build.gradle:

    configurations.all {
        resolutionStrategy.force 'androidx.appcompat:appcompat:1.6.1'
        // Add other libraries here if you see conflicts, e.g.:
        // resolutionStrategy.force 'androidx.core:core-ktx:1.12.0'
    }
    
  • Clean and rebuild your project
    Cached data often causes weird Gradle issues. Try these steps in order:

    1. Go to Build > Clean Project in Android Studio
    2. Then run Build > Rebuild Project
    3. If that doesn't work, delete the .gradle folder (project root) and build folder (both project root and app module), then click File > Sync Project with Gradle Files
  • Verify Gradle Plugin and Gradle version compatibility
    Mismatched Android Gradle Plugin (AGP) and Gradle versions can break dependency resolution. Go to File > Project Structure > Project and make sure your AGP version pairs correctly with the Gradle version (e.g., AGP 8.3 requires Gradle 8.4).

  • Align compileSdk, targetSdk, and dependency versions
    Ensure your compileSdkVersion is the highest value in your build config, and set targetSdkVersion to match it. All your dependencies should be built for at least your compileSdkVersion to avoid conflicts.

If you're still stuck, feel free to share your module-level build.gradle code (redact any sensitive details) and the full error log—we can troubleshoot further!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:55:01