androidkotlingradledependenciesimplementation

how do i implement " implementation 'com.google.mlkit:barcode-scanning:17.2.0' " in the new gradle 8.4 as it seems to be in different format


hi i am fairly new to android studios, i was following a tutorial on scanning qr code, the first step requires me to add "implementation 'com.google.mlkit:barcode-scanning:17.2.0' into my dependencies however, the format seems to be different enter image description here

enter image description here how do i correctly implement it, do i have to change the library


Solution

  • Your gradle file is written in Kotlin, not Groovy. You can determine that from the file extension: Kotlin scripts have an additional .kts at the end. The dependency you try to add is written with the Groovy syntax, though.

    The syntax is pretty similar and most of the scripts will run either way, but especially for the implementation you need to make sure that you use parentheses. And where the Groovy snytax allows you to use single quotes or double quotes to terminate strings, the Kotlin syntax only allows double quotes.

    This should work:

    implementation("com.google.mlkit:barcode-scanning:17.2.0")
    

    That said, in addition to the above, your app seems to use version catalogs. That means that you separate the declaration and the use of a dependency. Although the above will work, to make it more aligned with the other dependencies you should follow the Migration Guide for Version Catalogs.