在 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/