Android Studio内搜索Maven Central依赖库无结果问题求助
Hey there! I totally get the frustration when you can't find libraries like ButterKnife using Android Studio's built-in dependency search. Let's walk through the most common fixes to get this working:
First, verify your project includes Maven Central in its repository list
Android Studio relies on the repositories configured in your project to search for libraries. For newer projects (using Android Studio Arctic Fox+), check your project'ssettings.gradlefile and make suremavenCentral()is listed under thedependencyResolutionManagementblock:dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() // This line is critical for accessing Maven Central libraries } }For older projects (using a project-level
build.gradle), ensuremavenCentral()is added in theallprojects > repositoriessection instead.Check Android Studio's library search settings
Sometimes the search scope is restricted by default. Here's how to fix it:- Open Android Studio's Settings (File > Settings on Windows/Linux; Android Studio > Settings on Mac)
- Navigate to Build, Execution, Deployment > Build Tools > Gradle > Android Studio Library Search
- Make sure the box labeled Include Maven Central repository is checked
- Restart Android Studio to apply the change
Double-check the library's coordinates (or try manual search)
If you're searching for a specific library like ButterKnife, ensure you're using the correct group ID and artifact ID. For example, ButterKnife's full coordinates arecom.jakewharton:butterknife:[version]. You can try typing the full group ID + artifact ID in the search bar to narrow results.Fallback: Add the dependency manually
If the search still doesn't work, you can always add the dependency directly to your app module'sbuild.gradlefile. For ButterKnife, it would look like this (replace the version with the latest one you need):dependencies { implementation 'com.jakewharton:butterknife:10.2.3' annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' }After adding this, click the "Sync Now" button in the top-right corner of Android Studio to pull in the library.
内容的提问来源于stack exchange,提问作者user8965395

