老师我是用 android studio 开发 的 ,gradle已经导入 retrofit, 但是不能 import

来源:4-5 案例:使用 Retrofit 发送网络请求

lovejavacoffee

2021-06-20

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1’
classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath "com.squareup.retrofit2:retrofit:2.6.2"
    classpath "com.squareup.retrofit2:converter-gson:2.6.2"
    classpath "com.google.code.gson:gson:2.8.1"

}

}

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

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

写回答

1回答

bennyhuo

2021-06-20

可能是因为jcenter,改成mavenCentral试试。jcenter下线了,回头我把代码更新下

0
2
qq_忘记
回复
lovejavacoffee
貌似老师看错了,你这是顶层的build.gradle吧?这里配置的是gradle脚本的依赖而不是你源码的依赖。所以要么在allprojects下配置全局dependencies,要么直接去子module下的build.gradle里面配置dependencies
2023-01-18
共2条回复

学会Kotlin 突破开发语言瓶颈

如果有一门语言可以取代Java,那么它一定是Kotlin。

1772 学习 · 486 问题

查看课程