Retrofit 2依赖关系

问题描述:

我试图在我的项目中添加Retrofit2。我做这样的动作:Retrofit 2依赖关系

  • 添加到我的的build.gradle依赖编译“com.squareup.retrofit2:改造:2.1.0” - 它不是全成(摇篮构建失败:文件不能被解析)
  • Updtaed Android SDK工具 - 它没有帮助
  • 投入Android和Gradle插件的项目配置版本:Android - 2.3.3,Gradle - 3.3。相同的结果:文件无法解析。
所有这些操作都不成功。我更新了Gradle(AS为我提供了,并且我接受了),但它也没有帮助。而现在,在所有行动之后,我的项目需要花费大量的时间来建立(在线工作模式下需要1个小时)。离线模式 - 2-3分钟。
有谁知道,发生了什么事?

更新:我gradle这个文件
模块

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.3" 
    compileOptions.encoding = "windows-1251" 

defaultConfig { 
    applicationId "ua.grant.smart" 
    minSdkVersion 14 
    targetSdkVersion 25 
    versionCode 3 
    versionName "1.5" 

} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
    } 
} 

dependencies { 
    compile 'com.android.support:support-core-ui:25.3.1' 
    compile 'com.android.support:support-fragment:25.3.1' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:design:25.3.1' 
} 
} 
dependencies { 
    compile 'com.google.android.gms:play-services-maps:10.2.6' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
} 

应用(顶层)

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

allprojects { 
    repositories { 
     jcenter() 
    } 
} 
+0

您可以发布您'build.gradle'文件(项目根目录和模块目录)? – Syex

+0

为什么你在一个gradle中声明2个'dependencies'?我虽然这是问题 – Flix

+0

好吧,我会尽力把它们放到一个块中。我应该在外部块中执行此操作,还是在android内部执行此操作? – user3533397

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.3" 
    compileOptions.encoding = "windows-1251" 

defaultConfig { 
    applicationId "ua.grant.smart" 
    minSdkVersion 14 
    targetSdkVersion 25 
    versionCode 3 
    versionName "1.5" 

} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
    } 
} 
dependencies { 
    compile 'com.android.support:support-core-ui:25.3.1' 
    compile 'com.android.support:support-fragment:25.3.1' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:design:25.3.1' 
} 
} 
dependencies { 
    compile 'com.google.android.gms:play-services-maps:10.2.6' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
} 
修改

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.3" 
    compileOptions.encoding = "windows-1251" 

defaultConfig { 
    applicationId "ua.grant.smart" 
    minSdkVersion 14 
    targetSdkVersion 25 
    versionCode 3 
    versionName "1.5" 

} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
    } 
} 
} 

dependencies { 
    compile 'com.android.support:support-core-ui:25.3.1' 
    compile 'com.android.support:support-fragment:25.3.1' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:design:25.3.1' 
    compile 'com.google.android.gms:play-services-maps:10.2.6' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
} 
+0

我试过了。它不适合我。相同的结果:未能解决。项目在1小时内建成。 – user3533397

+0

@ user3533397尝试使缓存无效。 '文件 - >使缓存无效/重新启动 - >无效并重新启动。我也更新了我的答案。从gradle执行新的更改,然后使缓存无效。 –

+0

我会试试这个。但为什么我的项目正在建设1小时? – user3533397