Android Studio 2.2.1依赖解析失败求助:无法解析com.android.support:appcompat-v7:28+
Hey there! I know how frustrating it is when you're just starting out with Android Studio and hit a dependency error that won't budge, even after trying all the common fixes online. Let's break down why this is happening with your specific setup and walk through the fixes that should get you back on track.
The Root of the Problem
Android Studio 2.2.1 is a pretty old release (from 2016), and com.android.support:appcompat-v7:28.+ is part of the final version of the Android Support Library. The main issues here are:
- Older AS versions don't automatically include Google's Maven repository, where these newer support libraries are hosted
- The
28.+wildcard version syntax can cause parsing glitches with the outdated Gradle plugin that comes bundled with AS 2.2.1
Step-by-Step Solutions
1. Swap the Wildcard Version for an Exact One
Instead of using 28.+, use the stable, final version number 28.0.0. Wildcards can create resolution confusion in older Gradle environments.
Update your app-level build.gradle dependencies block like this:
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:28.0.0' // 替换成具体版本号 testCompile 'junit:junit:4.12' }
2. Add Google's Maven Repository to Your Project-Level Build.Gradle
Older Android Studio defaults to only using JCenter, but support library 28 lives on Google's Maven repo. You need to add this repository in both sections of your project-level build.gradle:
buildscript { repositories { jcenter() maven { url 'https://maven.google.com' } // 添加这一行 } dependencies { classpath 'com.android.tools.build:gradle:2.2.1' } } allprojects { repositories { jcenter() maven { url 'https://maven.google.com' } // 这里也要添加 } }
3. Double-Check Build Tools Compatibility
Your current buildToolsVersion "28.0.3" works with compileSdkVersion 28, but if you still run into issues, try matching it exactly to the support library version:
android { compileSdkSdkVersion 28 buildToolsVersion "28.0.0" // 修改为匹配版本 // ... 其他配置保持不变 }
4. Clear Caches and Rebuild
Older AS versions are prone to caching bugs. Try these steps to wipe stale data:
- Go to
Build -> Clean Project - Then run
Build -> Rebuild Project - If that fails, manually delete the
.gradlefolder in your project root and thebuildfolder inside your app module, then restart Android Studio.
Why This Works
Adding Google's Maven repository gives Android Studio access to the support library files it couldn't locate before. Using an exact version number eliminates any ambiguity that the wildcard might cause with the outdated Gradle plugin included in AS 2.2.1.
内容的提问来源于stack exchange,提问作者nhu bui

