I can't add jitpack to build.gradle.kts it shows an error " Unexpected tokens (use ';' to separate expressions on the same line) "
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
I can't add jitpack to build.gradle.kts it shows an error " Unexpected tokens (use ';' to separate expressions on the same line) "
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
Support for Kotlin Gradle scripts is fairly new in Android — for example, Android Studio only added support for it in version 4.0. Most of the instructions that you will see online will be for Groovy Gradle scripts, and you will need to make some minor conversions.
In this case, this Groovy:
maven { url "https://jitpack.io" }
...turns into this Kotlin:
maven { url = uri("https://jitpack.io") }
Problem might be .. as you mentioned that the problem is in "in build.gradle.kts" this means you are using kotlin gradle script.
So, simply change maven { url "https://jitpack.io" }
to maven { url = uri("https://jitpack.io") }
.
Or,
Rather than you can also skip adding maven { url = uri("https://jitpack.io") }
in build.kts and simply go to settings.gradle and add this dependency here : -
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url = uri("https://jitpack.io") } // Here is your dependency
} }
Gradle 8.4 dependency use TOML Kotlin
setting.gradle.kts
, Here must register jitpack :
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
libs.versions.toml: below Gradle Script, there is a file is called TOML.In this version of Gradle, all the decencies must determine in this file by URL, version.(example: GitHub)
[versions]
advanced_menu = "1.0.0"
agp = "8.3.0-alpha17"
[libraries]
advanced_menu_mori = { module = "com.github.Mori-hub:Advanced_Menu", version.ref = "advanced_menu" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
3.build.gradle.kts(:app): Finally, add new lib in the dependencies by new pattern ->
libs.name is defined in toml file separated by dot
dependencies {
implementation(libs.androidx.core.ktx)
implementation (libs.advanced.menu.mori)
}
Even though all the above answers are correct in their own way, just wanted to highlight that
Gradle Script files written using the Kotlin DSL do not accept a single quote (') for defining strings. You should use double quotes (") wherever applicable. And also, you should use braces with the because
, implementation
and api
keywords
For example
implementation 'com.simpl.android:fingerprintSDK:1.1.2' {
because 'We use Simpl SDK for Payment'
}
is invalid
But
implementation("com.simpl.android:fingerprintSDK:1.1.2") { // Replaced with brackets and double quotes
because("We use Simpl SDK for Payment")
}
is valid
© 2022 - 2024 — McMap. All rights reserved.
maven { url = uri("https://jitpack.io") }
. See the Gradle documentation. – Aubergine