0

Hello there after adding dependency of paging

val paging_version = "3.1.0"

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

I'm getting this error

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)

Vasant Raval
  • 257
  • 1
  • 12
  • 31

3 Answers3

2

There's 2 different kinds of migrating to kotlin for android projects.

What you did is migrate your code from java to kotlin. This is what people usually mean when they want to migrate their project to kotlin.

This by itself doesn't change the gradle file to kotlin. The code you tried is applying kotlin to the gradle file. It is possible to change to kotlin (instead of groovy, which you probably have now) but that's a different process.

The groovy equivalent of

val paging_version = "3.1.0"

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

would be

def paging_version = "3.1.0"

implementation "androidx.paging:paging-runtime:${paging_version}"
Ivo
  • 18,659
  • 2
  • 23
  • 35
1

I have added it like this and it works:

implementation 'androidx.paging:paging-runtime-ktx:3.1.0'
F.Mysir
  • 2,838
  • 28
  • 39
  • just want to ask something, i have recently converted my java project into kotlin , but because the entire project is not converting at the same time I converted individual java files to kotlin , is there any way to implement all the kotlin project structure to my project , because I'm facing some issues , one after another – Vasant Raval Nov 25 '21 at 13:19
  • and because I'm very beginner i don't know what things are important in kotlin that has to be added – Vasant Raval Nov 25 '21 at 13:19
  • Mate its been 2 years I have swithed from Java to Kotlin. Kotlin is so much better! I do not know... Just learn from the beginning Kotlin it worth it :) – F.Mysir Nov 25 '21 at 13:22
  • YUp, but I think you didn't understand my question properly, for eg if we create a kotlin project there will be some files that are specific to kotlin projects, now as my project was java and I converted individual files to kotlin , there will be probably some files that may be missing for a kotlin project, like Java folder should be Kotlin, etc – Vasant Raval Nov 25 '21 at 13:28
  • so is there any way that i can convert my project properly to a kotlin project – Vasant Raval Nov 25 '21 at 13:30
  • Hi, this is a big discussion. And there is not one answer to your question. It depends is the answer. Keep in mind that android studio's kotlin project can compile java also. You do not have to convert everything to kotlin. – F.Mysir Nov 25 '21 at 14:25
  • @F.Mysir can you please see this [issue](https://stackoverflow.com/q/69755212/11560810) – Kotlin Learner Jan 09 '22 at 00:29
1

Use this :

def paging_version = "3.1.0"

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