Vlad
11/08/2023, 3:18 PMkotlin {
androidTarget() // <-- please register this Android target
}
When if I put androidTarget()
gradle says
Unresolved reference: androidTarget
I cleaned my cache.
And I have the template project from the Jetbrains wizzard tool which works just fine with androidTarget().
I am missing something I don't understand what exactly.
kotlin.version=1.9.20
agp.version=8.1.2
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
Any hints?Vlad
11/08/2023, 3:22 PMPablichjenkov
11/08/2023, 3:23 PMVlad
11/08/2023, 3:24 PMPablichjenkov
11/08/2023, 3:27 PMPablichjenkov
11/08/2023, 3:28 PMVlad
11/08/2023, 3:28 PMkotlin("jvm").version(kotlinVersion)
kotlin("multiplatform").version(kotlinVersion)
kotlin("plugin.serialization").version(kotlinVersion)
kotlin("native.cocoapods").version(kotlinVersion)
kotlin("android").version(kotlinVersion)
id("com.android.application").version(agpVersion)
id("com.android.library").version(agpVersion)
id("org.jetbrains.compose").version(composeVersion)
id("com.google.gms.google-services").version(googleServicesVersion)
id("dev.icerock.mobile.multiplatform-resources").version(mokoResVersion)
Nothing specific. Unless Moko somehow breaks everything 😄Vlad
11/08/2023, 3:29 PMbuild.gradle.kts:18:5: Unresolved reference: applyDefaultHierarchyTemplate
The funny story is that targetHierarchy.default()
says it is deprecated, use applyDefault.. But it can't be appliedPablichjenkov
11/08/2023, 3:31 PMVlad
11/08/2023, 3:31 PMplugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
kotlin("native.cocoapods")
id("com.android.library")
id("org.jetbrains.compose")
id("app.cash.sqldelight").version(Versions.sqlDelight)
id("dev.icerock.mobile.multiplatform-resources")
id("com.google.gms.google-services")
}
shared gradlePablichjenkov
11/08/2023, 3:32 PMVlad
11/08/2023, 3:33 PMPablichjenkov
11/08/2023, 3:33 PMPablichjenkov
11/08/2023, 3:34 PMVlad
11/08/2023, 3:35 PMVlad
11/08/2023, 3:35 PMVlad
11/08/2023, 3:36 PMPablichjenkov
11/08/2023, 3:42 PMPablichjenkov
11/08/2023, 3:42 PMVlad
11/08/2023, 3:43 PMVlad
11/08/2023, 3:43 PMPablichjenkov
11/08/2023, 3:44 PMPablichjenkov
11/08/2023, 3:44 PMVlad
11/08/2023, 3:45 PMPablichjenkov
11/08/2023, 3:48 PMVlad
11/08/2023, 4:13 PMandroidTarget()
in shared
because my shared has id("com.android.library")
plugin. And seems like only android.application must be used for androidTarget()
.
Since I have androidApp module, I replaced in it the kotlin("android")
plugin to
kotlin("multiplatform")
and added.
kotlin {
androidTarget()
sourceSets {
val androidMain by getting {
dependencies {
implementation(project(":shared"))
}
}
}
}
This setup can be seen in the compose-multiplatform-ios-android-template which I used to start the project.
Seems like JB has 2 different templates at the moment and I have no clue where they are going. But seems like I can't migrate to the gradle hierarchies just now. At least it won't be easy coz I am not smart enough to do so.
It builds for Android atm, will check iOSPablichjenkov
11/08/2023, 5:09 PMapplyDefaultHierarchyTemplate()
In your Gradle , and remove the Android plugins , see what happens.
Check this build.gradle file. It works for me:
https://github.com/pablichjenkov/component-toolkit/blob/master/component-toolkit/build.gradle.ktsVlad
11/08/2023, 5:18 PM/shared/build.gradle.kts:28:5: Unresolved reference: applyDefaultHierarchyTemplate
Although I can apply it for androidApp moduleVlad
11/08/2023, 5:22 PMPablichjenkov
11/08/2023, 5:25 PMVlad
11/08/2023, 5:28 PMThe Default Kotlin Hierarchy Template was not applied to 'project ':shared'':
Explicit .dependsOn() edges were configured for the following source sets:
[iosArm64Main, iosMain, iosSimulatorArm64Main, iosX64Main]
Consider removing dependsOn-calls or disabling the default template by adding
'kotlin.mpp.applyDefaultHierarchyTemplate=false'
to your gradle.properties
And iOS won't build with that.Pablichjenkov
11/08/2023, 5:29 PMVlad
11/08/2023, 5:30 PMapplyDefaultHierarchyTemplate()
Pablichjenkov
11/08/2023, 5:31 PMVlad
11/08/2023, 5:33 PMPablichjenkov
11/08/2023, 5:34 PMVlad
11/08/2023, 5:41 PMcommonMain.dependencies {
I can't even import the .dependencies extension. Something is wrong with my gradlePablichjenkov
11/08/2023, 5:46 PMPablichjenkov
11/08/2023, 5:48 PMVlad
11/08/2023, 5:49 PMdistributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
this?Pablichjenkov
11/08/2023, 5:51 PMVlad
11/08/2023, 5:51 PMVlad
11/08/2023, 5:52 PMVlad
11/08/2023, 5:52 PMPablichjenkov
11/08/2023, 5:52 PMVlad
11/08/2023, 5:53 PMplugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
kotlin {
jvmToolchain(17)
}
It has thisVlad
11/08/2023, 5:54 PMPablichjenkov
11/08/2023, 5:54 PMPablichjenkov
11/08/2023, 5:56 PMVlad
11/08/2023, 5:57 PMVlad
11/08/2023, 5:57 PMVlad
11/08/2023, 5:58 PMVlad
11/08/2023, 6:02 PMVlad
11/08/2023, 6:02 PMVlad
11/08/2023, 6:02 PMLandry Norris
11/08/2023, 6:03 PMandroid
, which works for me. It just warns about deprecation.Pablichjenkov
11/08/2023, 6:08 PMJeff Lockhart
11/08/2023, 6:15 PMI can't useThis isn't true.inandroidTarget()
because my shared hasshared
plugin. And seems like only android.application must be used forid("com.android.library")
androidTarget()
androidTarget()
can be applied to either a Android application or library.
I wonder if having buildSrc module breaks everythingThis is very likely the case. It seems as if you have multiple versions of the Kotlin Gradle plugin being applied, an older version that doesn't have
androidTarget()
or applyDefaultHierarchyTemplate()
.Vlad
11/08/2023, 6:16 PMJeff Lockhart
11/08/2023, 6:25 PMbuildSrc
in my library with version catalogs, which don't work well together out of the box currently, but this workaround helps.
You can check out how I'm configuring the Kotlin Gradle plugin version in my library with buildSrc
. It's being added to the classpath from the version catalog here. Then when it's applied, it doesn't use an explicit version.Jeff Lockhart
11/08/2023, 6:41 PMandroidTarget()
API, likely because an older KGP was being applied. In some cases it was the fault of another plugin they were using, so you might try removing other plugins until you identify the source. Also, see if there are updated plugin versions.Vlad
11/09/2023, 2:35 PMVlad
11/09/2023, 3:38 PMPablichjenkov
11/09/2023, 3:57 PMVlad
11/09/2023, 4:00 PMVlad
11/09/2023, 4:00 PMVlad
11/09/2023, 4:46 PMid("app.cash.sqldelight").version(Versions.sqlDelight)
with id("app.cash.sqldelight")
in my shared build.gradle (removed the version).
2. Added id("app.cash.sqldelight").version(sqldelightVersion)
into plugins {} in settings.gradle for the project
3. Added id("app.cash.sqldelight").apply(false)
into project's build.gradle.
That is it.
2 days. And I still have no clue why exactly.Jeff Lockhart
11/09/2023, 4:52 PMapply false
can be added. Whenever a plugin is applied in a module build.gradle configurations, no version should be specified, as it will use the version introduced on the classpath already.
I've found it best to follow this rule with all plugins, whether you think you're applying it only in a single module or not because it's possible other plugins have side effects of introducing another version where you don't expect. So by declaring it yourself at the top level, you maintain control of the version.Vlad
11/09/2023, 4:54 PMVlad
11/10/2023, 11:21 AMAdded id("app.cash.sqldelight").apply(false) into project's build.gradle.
would be already sufficient 🤦♂️ .
I remember explicitly not adding it because I thought since I am not applying the SQLDelight to whole project but only to shared, I don't need it lmao.