electrolobzik
05/23/2024, 7:01 AM1.9.21
to 1.9.23
or 2.0.0
in a KMM project I am getting errors. For 1.9.23
the error is
org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'ivy' was added by build file 'app/build.gradle.kts'
...
and for `2.0.0`:
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
> org.jetbrains.kotlin.konan.target.KonanTarget$IOS_ARM32
The gradle plugin version is 8.3.1
. What can be the reason? 🧵electrolobzik
05/23/2024, 7:04 AMkotlin {
androidTarget()
iosX64()
iosArm64()
iosSimulatorArm64()
Adam S
05/23/2024, 7:14 AMsettings.gradle.kts
?Adam S
05/23/2024, 7:19 AMelectrolobzik
05/23/2024, 9:44 AMimport java.net.URI
pluginManagement {
repositories {
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
google()
mavenCentral()
gradlePluginPortal()
}
includeBuild("buildsystem/convention")
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}
}
Adam S
05/23/2024, 10:03 AMdependencyResolutionManagement {}
to include the Yarn and NPM repos:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
//region Declare the Node.js & Yarn download repositories
// <https://youtrack.jetbrains.com/issue/KT-55620/>
exclusiveContent {
forRepository {
ivy("<https://nodejs.org/dist/>") {
name = "Node Distributions at $url"
patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
metadataSources { artifact() }
content { includeModule("org.nodejs", "node") }
}
}
filter { includeGroup("org.nodejs") }
}
exclusiveContent {
forRepository {
ivy("<https://github.com/yarnpkg/yarn/releases/download>") {
name = "Yarn Distributions at $url"
patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
metadataSources { artifact() }
content { includeModule("com.yarnpkg", "yarn") }
}
}
filter { includeGroup("com.yarnpkg") }
}
//endregion
}
}
electrolobzik
05/23/2024, 12:06 PMAbhijeet Kumar
05/23/2024, 12:10 PMAn exception occurred applying plugin request [id: 'compositebuild.multiplatform.root']
> Failed to apply plugin 'compositebuild.multiplatform.root'.
> Could not resolve all dependencies for configuration ':kmm_umbrella:detachedConfiguration4'.
> Could not find :kotlin-native-prebuilt-macos-aarch64:1.9.24.
Required by:
project :kmm_umbrella
The project builds and runs perfectly in my device though.electrolobzik
05/23/2024, 12:15 PM// workaround for <https://youtrack.jetbrains.com/issue/KT-51379>
exclusiveContent {
forRepository {
ivy("<https://download.jetbrains.com/kotlin/native/builds>") {
name = "Kotlin Native"
patternLayout {
// example download URLs:
// <https://download.jetbrains.com/kotlin/native/builds/releases/1.7.20/linux-x86_64/kotlin-native-prebuilt-linux-x86_64-1.7.20.tar.gz>
// <https://download.jetbrains.com/kotlin/native/builds/releases/1.7.20/windows-x86_64/kotlin-native-prebuilt-windows-x86_64-1.7.20.zip>
// <https://download.jetbrains.com/kotlin/native/builds/releases/1.7.20/macos-x86_64/kotlin-native-prebuilt-macos-x86_64-1.7.20.tar.gz>
listOf(
"iosX64",
"iosArm64",
"iosSimulatorArm64",
"macos-x86_64",
"macos-aarch64",
"osx-x86_64",
"osx-aarch64",
"linux-x86_64",
"windows-x86_64",
).forEach { os ->
listOf("dev", "releases").forEach { stage ->
artifact("$stage/[revision]/$os/[artifact]-[revision].[ext]")
}
}
}
metadataSources { artifact() }
}
}
filter { includeModuleByRegex(".*", ".*kotlin-native-prebuilt.*") }
}
And it didn’t give any affectelectrolobzik
05/23/2024, 12:16 PMAbhijeet Kumar
05/23/2024, 12:22 PMclass KotlinMultiplatformConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform")
apply("org.jetbrains.kotlin.native.cocoapods")
}
version = libs.findVersion("kmm_root_module_version")
extensions.configure<KotlinMultiplatformExtension>() {
applyDefaultHierarchyTemplate()
if (pluginManager.hasPlugin("com.android.library")) {
androidTarget()
}
listOf(
// iosX64(), -- iOS simulator running on Intel-based Macs.
iosArm64(), // -- physical iOS devices (iPhones, iPads) using the Arm64 architecture.
// iosSimulatorArm64(), -- iOS simulator running on Apple Silicon Macs (M1, M2, etc.).
).forEach { target ->
target.binaries.framework {
baseName = path.substring(1).replace(':', '-')
}
}
}
extensions.configure<KotlinMultiplatformExtension> {
androidTarget{
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
}
extensions.configure<LibraryExtension> {
compileSdk = Versions.COMPILE_SDK
defaultConfig.minSdk = Versions.MIN_SDK
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
}
}
Abhijeet Kumar
05/24/2024, 2:21 AMAdam S
05/24/2024, 6:49 AMdependencyResolutionManagement {}
with repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
or repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
, then you should specify the Kotlin/Native repos https://youtrack.jetbrains.com/issue/KT-51379/Build-fails-when-using-RepositoriesMode.FAILONPROJECTREPOS-with-kotlin-multiplatform-projects#focus=Comments-27-6548690.0-0electrolobzik
05/24/2024, 6:50 AMAdam S
05/24/2024, 6:52 AMrepositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
will always fail when using Kotlin 1.x and native targets, or when using Kotlin 1.x or 2.x with JS targets. Instead use repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
.electrolobzik
05/24/2024, 6:53 AMAdam S
05/24/2024, 6:54 AMmavenCentral()
and FAIL_ON_PROJECT_REPOS
.Adam S
05/24/2024, 7:03 AMRepositoriesMode.PREFER_SETTINGS
, and add Node/Yarn Ivy repos, and Maven Central
• "I'm using KGP 1.x and Native and/or JS targets" → You must use RepositoriesMode.PREFER_SETTINGS
, and add Kotlin/Native Ivy repos, and add Node/Yarn Ivy repos, and Maven Central
• "I'm using KGP 2.x and Native targets (no JS targets)" → You may use any RepositoriesMode
, and add Maven CentralAbhijeet Kumar
05/24/2024, 7:32 AMAdam S
05/24/2024, 8:05 AM