【发布时间】:2018-05-25 13:28:40
【问题描述】:
我有一个非常简单的问题。我是一名 Android 开发人员,在休息 6 个月后重返开发工作,并且像往常一样,一切都发生了明显的变化。这是我的问题:
- 在 Android Studio 3.1.2 上启动一个新的 Android 项目
- 默认 Gradle 插件是 3.1.2
- 为应用的 build.gradle 添加了 retrofit2 依赖项
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
- 开始 gradle 同步
无法解析 ':app@debug/compileClasspath' 的依赖关系:可以 无法解析 com.squareup.retrofit2:retrofit:2.4.0。打开文件显示 详情
无法解决依赖关系 ':app@debugAndroidTest/compileClasspath': 无法解析 com.squareup.retrofit2:retrofit:2.4.0。打开文件显示详情
无法解决依赖关系 ':app@debugUnitTest/compileClasspath': 无法解析 com.squareup.retrofit2:retrofit:2.4.0。打开文件显示详情
无法解析 ':app@release/compileClasspath' 的依赖关系: 无法解析 com.squareup.retrofit2:retrofit:2.4.0。打开文件 显示详情
无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 com.squareup.retrofit2:retrofit:2.4.0。打开文件显示详情
我阅读了有关 Gradle 插件 3 迁移的整篇文章。没用。
项目构建.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用级 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
【问题讨论】:
-
向我们展示您的项目和应用级别的 build.gradle 文件
-
我添加了您要求的文件。真的没有任何并发症。这只是一个简单的示例项目,只添加了一行依赖项。