android - 无法为类型为 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 的对象获取未知属性 'okhttpVersion'

标签 android kotlin dependencies retrofit build.gradle

build.gradle 文件中添加了以下依赖项,用于在我的新 Kotlin 项目中实现 Retrofit API 调用。

    implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
    implementation ("com.squareup.retrofit2:retrofit:$retrofitVersion"){
        exclude module: 'okhttp'
    }
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"

同步后会显示下面提到的错误。

Could not get unknown property 'okhttpVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

工作室指向错误线是,

implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"

请给出任何解决方案。

最佳答案

像这样定义版本值

def okhttpVersion = "3.10.0"
def retrofitVersion = "2.4.0"
implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
implementation ("com.squareup.retrofit2:retrofit:$retrofitVersion"){
    exclude module: 'okhttp'
}
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"

尝试添加依赖的硬编码版本

implementation "com.squareup.okhttp3:okhttp:3.10.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.10.0"
implementation ("com.squareup.retrofit2:retrofit:2.4.0"){
    exclude module: 'okhttp'
}
implementation "com.squareup.retrofit2:converter-gson:2.4.0"

不要忘记清理和重建...

关于android - 无法为类型为 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 的对象获取未知属性 'okhttpVersion',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49788747/

相关文章:

android - 解析单个对象响应

android - Gallery setSelection 不会触发图像选择器

android - 当从 Android Studio 签名生成 .apk 时,zipalign 会自动执行吗?

android - 由于找不到元素,Calabash Android 随机失败

android - 如何为 material.Slider View 创建绑定(bind)适配器?

java - eclipse中maven快照的超时时间是多少?

安卓 Kotlin : Error Unresolved reference: DaggerAppComponent

android - 我可以将用 Kotlin 编写的库导入到我的 android 项目中吗(使用 java)

grails - 排除 Grails 构建范围依赖项

maven - Hadoop Maven 依赖错误