Unresolved reference: ExposedDropdownMenuBox in Compose for Desktop - kotlin

I need to implement a drop down menu for Windows App which is based on Compose for Desktop
For that I am trying to use ExposedDropdownMenuBox
But I am getting error:
Unresolved reference: ExposedDropdownMenuBox
Following is the code:
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = {
expanded = !expanded
}
) {
// TextFeild implementation
}
And the file build.gradle.kts contains following:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.1"
}
group = "com.op.bgmi"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "App"
packageVersion = "1.0.0"
}
}
}
Am I missing something, please advice.
What is the correct approach to have drop down menu box in Compose for Desktop

ExposedDropdownMenuBox is currently not available for Desktop.
You can check the location of the item in the AndroidX repository: it is located in androidMain folder, which makes it only available for the Android platform. It uses some Android-specific APIs under the hood, which makes it impossible to use from the desktop.
Perhaps it will be rewritten and made cross-platform before the Experimental annotation is removed, or there will be a separate implementation for Desktop in the future. You can follow updates here.
For now, you can use DropdownMenu as shown in this answer.

Related

(KotlinSourceSet with name 'androidMain' not found.) How can I add android as a build target to a Kotlin Multiplatform project

I am trying to add android() as a build target to a Kotlin Multiplatform library so that I can add a specific library for the android target. All the other targets (jvm, linux, ios) work fine, but android seems to have issues, because the KotlinSourceSet is not being create like the others.
That's where I get the error:
KotlinSourceSet with name 'androidMain' not found.
I wonder, do I have to add the SourceSet manually? Am I missing some crucial build step?
Here is my gradle.build.kts
plugins {
id("maven-publish")
kotlin("multiplatform") version "1.8.0"
}
buildscript {
repositories {
google()
}
dependencies {
classpath ("com.android.tools.build:gradle:4.2.2")
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
}
}
group = "zzz.xxxx"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
kotlin {
jvm()
linuxX64("linux")
ios()
android()
sourceSets {
val commonMain by getting {
dependencies {
implementation("...")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation("...")
}
}
val androidMain by getting {
dependencies {
implementation ("...")
}
}
val jvmTest by getting
}
}
I tried adding a androidMain folder, but it is not getting recognized as a KotlinSourceSet. Non of the resources online seem to help either.
To add android as a build target your need to setup android-gradle-plugin first.
With example setting of android plugin gradle.build.kts will be:
plugins {
id("maven-publish")
kotlin("multiplatform") version "1.8.0"
id("com.android.library") version "7.3.0" // (1) add plugin
}
//...
// (2) setup plugin
android {
compileSdk = 33
defaultConfig {
minSdk = 24
multiDexEnabled = true
}
sourceSets {
getByName("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
}
}
}
UPDATE
Before you are adding Android Gradle plugin:
Check that Google Maven repository is listed in your settings.gradle(.kts) file
Check the Android Gradle plugin is added to the project build.gradle(.kts) file
Check the Android Gradle plugin is compatible with your Gradle version

IntelliJ IDEA could not found the kotlin test dependency Library, but I have kotlin("test") for gradle.build.ks

I created a kotlin project through the project creation wizard of Intellij IDEA.
I just created a test file to verify the demo of kotlin official website.
A demo for Intellij IDEA, but it not find to 'kotlin.test.Test'.
internal class ATest {
#kotlin.test.Test
fun sum() {
}
}
IDEA UI IMAGE
This is my 'gradle.build.ks' file.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

Kotlin NoSuchMethodError after installing a library that enables a plugin

I want to experience a library called arrow analysis
My build.gradle.kts file looks as follows:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("io.arrow-kt:arrow-core:1.1.2")
}
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
after an attempt to build the project, I get the following error:
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.psi.KtExpression org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt.getReceiverExpression(org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)'
at arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.KotlinResolvedCall.getReceiverExpression(KotlinResolvedCall.kt:37)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.allArgumentExpressions(ResolvedCallUtils.kt:75)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.arg(ResolvedCallUtils.kt:119)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.controlFlowAnyFunction(Expressions.kt:438)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.checkCallExpression(Expressions.kt:397)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.fallThrough(Expressions.kt:260)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.access$fallThrough(Expressions.kt:1)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:244)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:157)
at arrow.meta.continuations.ContSeq$flatMap$1.invokeSuspend(ContSeq.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
I checked the source code, and everything seems to be in place. Did I something wrong as per the instructions to install this library which is denoted as follows:
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
You need to apply the plugin inside the plugins block and in the same fashion you're applying the Kotlin JVM plugin.
They mention to use it like this on their official docs
plugins {
kotlin("multiplatform") version "1.6.21"
// other plugins
id("io.arrow-kt.analysis.kotlin") version "2.0.2"
}
buildscript {
repositories {
mavenCentral()
}
}

build.gradle.kts following githubs guide: Configuring Gradle for use with GitHub Packages. But it fails finding the "from" function

I have a sample kotlin project that i am trying to get send to github as a package. Below is the contents of my buid.gradle.kts file. I am following this guide: https://docs.github.com/en/packages/guides/configuring-gradle-for-use-with-github-packages#example-using-kotlin-dsl-for-a-single-package-in-the-same-repository
But i can find any help as to why this error happens with the "from" function"
buid.gradle.kts content:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
repositories {
mavenCentral()
}
plugins {
kotlin("jvm") version "1.4.31"
`maven-publish`
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}
publications {
register("gpr") {
from(components["java"]) //This part fails with a Unresolved reference. None of the following
//candidates is applicable because of receiver type mismatch:
}
}
}
group = "me.jeppe"
version = "1.0-SNAPSHOT"
dependencies {
testImplementation(kotlin("test-junit"))
}
tasks.test {
useJUnit()
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}
After searching wide and far it appears that i need to write this:
register("gpr", MavenPublication::class)
instead of:
register("gpr")

Why do I get no main manifest attribute, in rome-utils-1.15.0.jar?

I am trying to use the rome rss library. However, when I go to execute my jar I get the error.
I am assuming it has something to do with my build.gradle.kts file. I have copied it here
buildscript {
repositories {
maven("https://plugins.gradle.org/m2/")
maven(url = "https://www.jitpack.io") {
name = "jitpack"
}
flatDir {
dirs("libs")
}
}
dependencies {
}
}
plugins {
application
kotlin("jvm") version "1.4.0"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
application {
mainClassName = "io.ktor.server.netty.EngineMain"
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url = uri("https://kotlin.bintray.com/ktor") }
maven(url = "https://www.jitpack.io") {
name = "jitpack"
}
}
tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveBaseName.set("freedom")
archiveClassifier.set("")
archiveVersion.set("1.1.0")
manifest {
attributes(mapOf("Main-Class" to application.mainClassName))
}
}
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("com.rometools:rome:1.15.0")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-core-jvm:$ktor_version")
implementation("io.ktor:ktor-gson:$ktor_version")
implementation("io.ktor:ktor-client-apache:$ktor_version")
implementation("io.ktor:ktor-html-builder:$ktor_version")
implementation("com.github.chimbori:crux:2.2.0")
implementation("org.jsoup:jsoup:1.13.1")
implementation("io.lettuce:lettuce-core:6.0.1.RELEASE")
implementation("org.jetbrains.exposed", "exposed-core", "0.28.1")
implementation("org.jetbrains.exposed", "exposed-dao", "0.28.1")
implementation("org.jetbrains.exposed", "exposed-jdbc", "0.28.1")
implementation("com.google.firebase:firebase-admin:7.0.1")
implementation("org.postgresql", "postgresql", "42.2.18")
implementation("com.zaxxer:HikariCP:3.4.5")
implementation("com.github.kittinunf.fuel:fuel:2.3.0")
implementation("com.github.kittinunf.fuel:fuel-gson:2.3.0")
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
}
kotlin.sourceSets["main"].kotlin.srcDirs("src")
kotlin.sourceSets["test"].kotlin.srcDirs("test")
sourceSets["main"].resources.srcDirs("resources")
sourceSets["test"].resources.srcDirs("testresources")
My app builds fine without this library. However, I need to use this particular library. I have tried steps in similar questions but they did not work. When trying to execute my program I get no main manifest attribute, in rome-utils-1.15.0.jar
The problem lies with shadowJar improperly building the Rome jar. This is something that must be taken up on the shadowJar's github.
I came across the same issue and I'm sure that problem is not in the build.gradle file.
I believe you want mainClass not mainClassName per Gradle user guide
So try
application {
mainClass = "io.ktor.server.netty.EngineMain"
}