首次构建Android Studio新项目时出现Failed to resolve: com.android.support错误求助
Hey there, let's dig into this generic Failed to resolve: com.android.support error you're hitting. It's extra tricky because it doesn't specify a particular library, but looking at your build config, I spot a few things that might be causing this. Here's what to try:
1. Fix the Typo in Constraint Layout Dependency
First, I noticed a critical mistake in your module-level build.gradle dependencies:
implementation 'com.android.support.constraint:constraint-list_item:1.0.2'
That should be constraint-layout, not constraint-list_item—there's no valid support library with that name. This invalid dependency is likely throwing off Gradle's resolution process entirely, leading to that vague generic error message. Replace it with:
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
2. Unify Dependency Syntax & Remove Duplicates
Android Studio 3.0+ recommends using implementation over the older compile keyword for dependencies. Let's update your module dependencies to follow this standard, and also remove the duplicate com.android.support:design entry:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation "com.android.support:appcompat-v7:26.1.0" implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:design:26.1.0' implementation 'com.android.support:support-v4:26.1.0' implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0' implementation 'de.hdodenhof:circleimageview:2.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' }
3. Clean & Refresh Gradle Caches
After fixing the dependency issues, do a full clean and rebuild to clear any cached bad data:
- Go to File > Invalidate Caches / Restart and confirm the action.
- Once Android Studio restarts, run Build > Clean Project.
- Finally, execute Build > Rebuild Project.
4. Verify SDK Repository Installation
Double-check that you have the correct support repositories installed for your SDK version:
- Open Tools > SDK Manager.
- Switch to the SDK Tools tab, check the box for Show Package Details.
- Ensure Android Support Repository (matching your
compileSdkVersion 26) and Google Repository are installed. If not, install them and sync your project again.
5. Confirm Repository Setup
Your top-level build.gradle already has google() and jcenter() configured in both buildscript and allprojects sections, which is correct for Android Studio 3.0+. Just make sure you're not behind a proxy that might block access to these repositories—if you are, configure proxy settings in Android Studio's preferences.
Give these steps a go—I'm willing to bet the typo in the constraint layout dependency was the root cause of that generic resolution error. If it still persists, let me know and we can troubleshoot further!
内容的提问来源于stack exchange,提问作者DrkStr

