无法解析retrofit2的依赖关系

问题描述 投票:0回答:5

我尝试将改装库导入我的gradle文件但不幸的是,我遇到了太多错误。

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.squareup.retrofit2:retrofit:2.4.0.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.squareup.retrofit2:retrofit:2.4.0.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.squareup.retrofit2:retrofit:2.4.0.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.squareup.retrofit2:retrofit:2.4.0.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.squareup.retrofit2:retrofit:2.4.0.

编辑这是我的app build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.practice"
    minSdkVersion 19
    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'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.dinuscxj:recyclerrefreshlayout:2.0.5'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:4.1.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'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.squareup.picasso:picasso:2.71828'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.vanniktech:emoji-one:0.5.1'
implementation 'net.danlew:android.joda:2.9.9.3'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
}

apply plugin: 'com.google.gms.google-services'

这是我的项目build.gradle

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:4.0.1'
  }
}

allprojects {
    repositories {
      google()
      jcenter()
  }
}

task clean(type: Delete) {
   delete rootProject.buildDir
}

我添加了最新版本的retrofit2,但仍然遇到这些错误。我寻找可能的解决方案,但我找不到任何东西。有人可以帮我解决这个问题吗?

android gradle retrofit2
5个回答
1
投票

试试这个

  implementation('com.squareup.retrofit2:retrofit:2.1.0') {
    // exclude Retrofit’s OkHttp dependency module and define your own module import
    exclude module: 'okhttp'
}
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'

和项目build.gradle

allprojects {
repositories {
    jcenter()
    google()
    mavenCentral()
    maven { url 'https://jitpack.io' }
}
}

0
投票

添加构建Gradle文件

'com.squareup.retrofit2:retrofit:2.4.0'

0
投票

尝试将此添加到模块(即app)级别gradle:

repositories {
    maven {
        mavenCentral()
    }
}

你也可以尝试:

转到文件/无效缓存重启


0
投票

我找到了解决方案。我忘了在设置 - >构建,执行,部署 - > Gradle - >离线工作中取消选中离线工作


0
投票

你可以添加这个插件是你的app build.gradle文件

implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'

你可以在所有项目中更改项目build.gradle文件,如下面的代码

 allprojects {
repositories {
    google()
    maven { url "https://jitpack.io" }
    jcenter()
} }
© www.soinside.com 2019 - 2024. All rights reserved.