无法为依赖类型的对象获取未知 属性 'implementation'

Could not get unknown property 'implementation' for object of type Dependency

添加分页依赖后你好

val paging_version = "3.1.0"

implementation("androidx.paging:paging-runtime:$paging_version")

我遇到了这个错误

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

Note: I have switched my project from java to kotlin ( because there is some issue the entire project cant be converted so I convert every java file one by one)

我是这样添加的并且有效:

implementation 'androidx.paging:paging-runtime-ktx:3.1.0'

使用这个:

def paging_version = "3.1.0"

implementation "androidx.paging:paging-runtime:$paging_version"

android 项目有 2 种不同的迁移到 kotlin 的方法。

您所做的是将您的代码从 java 迁移到 kotlin。这就是人们想要将他们的项目迁移到 kotlin 时通常的意思。

这本身不会将 gradle 文件更改为 kotlin。您尝试的代码是将 kotlin 应用于 gradle 文件。可以更改为 kotlin(而不是您现在可能拥有的 groovy),但这是一个不同的过程。

groovy 相当于

val paging_version = "3.1.0"

implementation("androidx.paging:paging-runtime:$paging_version")

会是

def paging_version = "3.1.0"

implementation "androidx.paging:paging-runtime:${paging_version}"