我有一个非常简单的问题 . 我是一名Android开发人员,经过6个月的休整后重返开发阶段并且像往常一样,一切都发生了变化 . 这是我的问题:
-
在Android Studio 3.1.2上启动一个新的Android项目
-
默认Gradle插件是3.1.2
-
为app的build.gradle添加了retrofit2依赖项
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
- 开始gradle sync
无法解析':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迁移的整篇文章 . 没有任何帮助 .
项目build.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
}
app level 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'
}
3 回答
我运行你的代码运行没有错误 . 尝试使高速缓存/重新启动无效:文件 - >使高速缓存/重新启动无效
如果您的PC在某些代理上运行,请在android studio中添加代理或检查您的互联网连接 . 对于代理,请按照以下步骤操作:文件 - >设置 - >外观和行为 - >系统设置 - > HTTP代理添加您的代理
否则请检查您的网络连接
您可以从here下载库作为jar文件然后将文件复制到Android Studio中的libs文件夹中 . 然后右键单击jar文件并单击
Here是向Android Studio添加库的完整说明
如果您还有问题,请告诉我
希望能帮助到你 .
快乐的编码