Gradle构建失败:无法找到com.android.volley:volley:1.1.1依赖文件
问题分析
构建失败的核心原因是无法解析com.android.volley:volley:1.1.1依赖,所有失败任务均由此引发。此外还存在两个次要问题:重复的Material组件依赖,以及已废弃的kotlin-android-extensions插件。
解决方案
1. 修复Volley依赖解析问题
两种可行方案:
- 方案A:更新Volley至最新稳定版
将依赖替换为当前最新版本(1.2.1),该版本在Maven仓库中可稳定获取:implementation 'com.android.volley:volley:1.2.1' - 方案B:确认项目级仓库配置
检查项目根目录下的build.gradle文件,确保repositories块包含google()和mavenCentral():buildscript { repositories { google() mavenCentral() } // 其他配置... } allprojects { repositories { google() mavenCentral() } }
2. 删除重复的Material组件依赖
dependencies块中同时引入了两个版本的Material组件,删除较旧的1.3.0-alpha02版本,保留稳定版1.6.1:
// 保留这一行 implementation 'com.google.android.material:material:1.6.1' // 删除这一行 // implementation 'com.google.android.material:material:1.3.0-alpha02'
3. 替换已废弃的kotlin-android-extensions插件
该插件已被官方废弃,建议迁移至View Binding:
- 在
app/build.gradle中移除id 'kotlin-android-extensions' - 启用View Binding:
android { // 其他配置... buildFeatures { viewBinding true } }
若需Parcelize功能,添加kotlin-parcelize插件:
plugins { // 其他插件... id 'kotlin-parcelize' }
修正后的完整app/build.gradle示例
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-parcelize' // 可选,用于Parcelize功能 } android { compileSdkVersion 30 defaultConfig { applicationId "com.example.todolist" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } buildFeatures { viewBinding true // 启用View Binding } } dependencies { implementation 'com.android.volley:volley:1.2.1' implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }
内容的提问来源于stack exchange,提问作者njiokm
相关产品推荐
相关产品推荐

