https://kotlinlang.org
Join Slack
What would be the right way to generate an UUID in kotlin?
a

Alin B.

over 7 years ago
What would be the right way to generate an UUID in kotlin?
a
a
+2
  • 4
  • 16
  • 11304
after updating my project to Kotlin 1.8.0 I'm getting the following build error: ```Execution failed...
j

Jorge Domínguez

over 2 years ago
after updating my project to Kotlin 1.8.0 I'm getting the following build error:
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: <https://kotl.in/gradle/jvm/toolchain>
but my Gradle config is:
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}
so I'm not sure where target 17 is setup, has somebody experienced the same error?
j
d
b
  • 3
  • 4
  • 10155
Anyone know how to solve `Cannot use @TaskAction annotation on method AbstractKotlinCompile.execute(...
d

dave08

over 2 years ago
Anyone know how to solve
Cannot use @TaskAction annotation on method AbstractKotlinCompile.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
when upgrading from an older AGP version to 8.0.2?
d
a
  • 2
  • 5
  • 9407
I am trying to use a preview JDK in my Kotlin compiler config, but I am getting a strange error. Has...
g

Gavin Ray

over 2 years ago
I am trying to use a preview JDK in my Kotlin compiler config, but I am getting a strange error. Has anyone seen this before:
val JDK_21_PATH = "/home/user/.sdkman/candidates/java/21.ea.6-open"

tasks.withType<org.jetbrains.kotlin.gradle.tasks.UsesKotlinJavaToolchain>().configureEach {
    kotlinJavaToolchain.jdk.use(JDK_21_PATH, JavaVersion.VERSION_21)
}
Execution failed for task ':app:compileKotlin'.
> Error while evaluating property 'compilerOptions.jvmTarget' of task ':app:compileKotlin'.
   > Failed to calculate the value of property 'jvmTarget'.
      > Unknown Kotlin JVM target: 21
g
t
  • 2
  • 37
  • 6846
Hey I am experiencing a serious issue - it looks like mocking answer for a parametrised suspended me...
i

igor.wojda

about 3 years ago
Hey I am experiencing a serious issue - it looks like mocking answer for a parametrised suspended method does not work as expected:
class ExampleUnitTest {
    private val repository = mockk<AlbumRepository>()

    private val cut = GetAlbumUseCase(repository)

    @Test
    fun `when execute return success`() {
        // given
        val albumName = "Thriller"
        val artistName = "Michael Jackson"
        val mbId = "123"

        // when
        val actual = runBlocking { cut.execute(albumName, artistName, mbId) }

        // then

    }
}
no answer found for: AlbumRepository(#1).getAlbumInfo(Thriller, Michael Jackson, 123, continuation {})
io.mockk.MockKException: no answer found for: AlbumRepository(#1).getAlbumInfo(Thriller, Michael Jackson, 123, continuation {})
	at app//io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:93)
The answer can't be found (most likely due to
continuation {}
param). I have crafted a sample project to reproduce this. Steps: 1. Open project using
Android Studio
2. Run
ExampleUnitTest
tests Can someone take a look? Is there any workaround?
TestMockk2.zip
i
c
n
  • 3
  • 14
  • 5934
I'm updating my multi-module multiplatform (android/ios/jvm) project from Kotlin 1.7.22 / Gradle 7.5...
r

ribesg

over 2 years ago
I'm updating my multi-module multiplatform (android/ios/jvm) project from Kotlin 1.7.22 / Gradle 7.5.1 to Kotlin 1.8.10 / Gradle 8.0 and have this issue:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
Anyone encountered this? It's a lint task so it still builds, but it looks weird. (see logs in thread)
r
m
+5
  • 7
  • 56
  • 5594
I’m getting `No tests found for given includes` when trying to run a single kotest test inside a gra...
b

bbaldino

over 3 years ago
I’m getting
No tests found for given includes
when trying to run a single kotest test inside a gradle project--I assume this must be something dumb I’m missing but after googling around a bit I still haven’t seen anything that addresses it. I do have
tasks.withType<Test>().configureEach {
    useJUnitPlatform()
}
in build.gradle.kts
b
s
  • 2
  • 66
  • 5536
I am trying to implement a Room database but my app crashes
j

Jetbrains Ttvna

about 2 years ago
I am trying to implement a Room database but my app crashes
not kotlin but kotlin colored 2
j
f
+2
  • 4
  • 33
  • 5511
How to scroll to a specific item of a lazy column? I am creating a lazy column based on my model whi...
m

Michael Paus

over 2 years ago
How to scroll to a specific item of a lazy column? I am creating a lazy column based on my model which describes a hierarchical structure with one selected item. (Think of a large book with thousands of pages subdivided into sections and sub-sections.) The column only unfolds and shows the elements which lead to the selected page. So far this is working nicely but then scrolling to the selected item seems to be strange. 1. How do you get at the index of an arbitrary item to be able to scroll to it? Is the below code the proposed way to get at it? 2. Where do you best place the below code (if it is correct) so that it is always executed after the composition because the index is only reliably available after it. 3. What rules does the
animateScrollToItem
follow? It does not seem to scroll the item to the top if this would result in blank space at the bottom of the column.
val index = listState.layoutInfo.visibleItemsInfo.filter {
    it.key == myModelState.selectedReference?.refId }.firstOrNull()?.index
index?.let { listState.animateScrollToItem(index = it) }
All examples I have seen so far only seem to handle the trivial case that you want to scroll to the first item which is simply not a realistic use-case for me.
☝️ 1
➕ 1
m
a
  • 2
  • 4
  • 5050
I need to get context in view model , I am trying to get using localcontext but it is keep giving er...
j

Jitendra

over 3 years ago
I need to get context in view model , I am trying to get using localcontext but it is keep giving error @composable invocation can only happen from the context of composable function, what is the best way to get context/activity instance in viewsmodel
j
f
+2
  • 4
  • 3
  • 4962
12Next

kotlinlang

A modern programming language that makes developers happier.

Powered by