https://kotlinlang.org logo
Join Slack
Powered by
# stackoverflow
  • r

    rss

    09/15/2025, 10:21 AM
    Detection of Unavailable Characters (Tofu Box) in a String I wanted to know what is the best way to detect whether a part of string has an unavailable character, '□' (tofu box or last resort character). So far it seems to be that we will have to parse all the strings and individually check for each character and whether or not it is a part of the Unicode Scalar. And since we are a business application that deals with a lot of data as strings, this will be rather performance heavy. So wanted to know if there were any other better or more efficient...
  • r

    rss

    09/15/2025, 11:01 AM
    Jetpack Compose Material 3: How to use Expressive style Pull-to-Refresh indicator with PullToRefreshBox? I'm updating my Jetpack Compose to use the latest Material 3 dependencies. material = "1.12.0" composeBom = "2025.07.00" compose-material3 = "1.4.0-alpha18" I wrote this before, But after upgrading the dependency,“LoadingIndicator()” turned red if (isRefreshing || scaleFraction() > 0f) { Box( Modifier .align(Alignment.TopCenter) .graphicsLayer { scaleX = scaleFraction() scaleY = scaleFraction() }...
  • r

    rss

    09/15/2025, 2:41 PM
    Mockk Static persists behavior across tests I have mocked a class as follows: @Before fun setup() { mockkStatic(MyUtils::class) } @After fun tearDown() { clearStaticMockk(MyUtils::class) } Then i define behavior of MyUtil's getUserObject() function in the Test 1 as follows - Test 1: val mockkUser = mockk(relaxed = true) every { mockkUser.getAddress(userId) } returns Address(1, 1) every { MyUtils.getUserObject(userId) } returns mockkUser In Test 2, i have similar setup, but here mockkUser.getAddress(userId) returns...
  • r

    rss

    09/15/2025, 3:41 PM
    Nav items of NavigationSuiteScaffold in Jetpack compose have misalignment by default I am using Adaptive Navigation (docs) and facing weird problem of icons being misaligned, I have tried icons from Icons class as well as Drawable res icons. Screenshot: Preview on portrait and landscape phone screen, and tablet, it is aligned in tablet only

    https://i.sstatic.net/Bq1Cpgzu.png▾

    real...
  • r

    rss

    09/15/2025, 7:41 PM
    How can I tie a coroutine's lifetime to the lifetime of an object? I have some code similar to this: class Foo { var x = 0 init { GlobalScope.launch { while (true) { delay(1000) x += 1 } } } } How can I ensure that the coroutine will be cancelled when its owning instance of Foo is garbage collected?
  • r

    rss

    09/16/2025, 4:21 AM
    Tensorflow lite sample code does not work from the tutorials https://ai.google.dev/edge/litert/models/signatures#java I have the model generated, I have the model loaded. I verified this because I can see the signatures that are available: I don't know what the encoded_result and decoded_result variables should be. Can someone give me a concrete example code? val encodeInput = mutableMapOf() val encodeOutput =...
  • r

    rss

    09/16/2025, 10:01 AM
    Should we implementation(project(":app")) in a dynamic feature? In the test project, we have app: the base application dynamicfeature: the dynamic feature module mylibrary: the kotlin library In dynamicfeature build.gradle.kts dependencies { implementation(project(":app")) ... In app build.gradle.kts android { dynamicFeatures += setOf(":dynamicfeature") ... } tasks.register("writeVersionSuffix") { doLast { var versionSuffix = getUnifiedVersionSuffix(1234) println("writeVersionSuffix versionSuffix:...
  • r

    rss

    09/16/2025, 11:01 AM
    FlutterPlugin never gets instantiated on android I am currently developing a flutter plugin that uses native components. iOS part works fine, the plugin is registered and messages pass through method channel. On Android however, things don't work. The plugin init method never gets called. It seems that the package is not imported, but that should have been done by Flutter by default. Any ideas where to look for? Thanks.
  • r

    rss

    09/16/2025, 1:01 PM
    The following error occurs when I tried to build the app: [closed] C:/Users/usr/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-android-extensions-runtime/1.9.22/ee3bc0c3b55cb516ac92d6a093e1b939166b86a2/kotlin-android-extensions-runtime-1.9.22.jar!/META-INF/kotlin-android-extensions-runtime.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
  • r

    rss

    09/16/2025, 1:41 PM
    Hide default splash screen Is it actually possible to completely hide or remove the default splash screen in Flutter? If yes, what are the correct steps to do it for both Android and iOS? This is my style.xml:

    enter image description here▾

    This is my launch_background.xml:

    enter image description here▾

  • r

    rss

    09/16/2025, 7:01 PM
    java.lang.NoSuchMethodError: void kotlinx.coroutines.CompletableDeferredImpl.initParentJob(kotlinx.coroutines.Job) when building Android project I am getting the following error when trying to build my Android project: Cause 1229: java.lang.NoSuchMethodError: "void kotlinx.coroutines.CompletableDeferredImpl.initParentJob(kotlinx.coroutines.Job)" at com.android.repository.impl.manager.RepoManagerImpl$AbstractLoadTask.(RepoManagerImpl.kt:352) ... BUILD FAILED in 1m 30s Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. It seems to be related to...
  • r

    rss

    09/16/2025, 7:41 PM
    How to send a GET request with multiple IDs from Android (Ktor) and receive it in Spring Boot (Kotlin)? I have an Android app written in Kotlin using Ktor client, and a Spring Boot backend written in Kotlin. I want to fetch user data for multiple IDs (say, 10 IDs) in one GET request. I’m not sure how to send a list of integers in the GET request and how to receive it properly in Spring Boot. What I tried: Android + Ktor client: val ids = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val response: List = client.get("https://myserver.com/users") { parameter("ids", ids.joinToString(",")) // sending as...
  • r

    rss

    09/17/2025, 2:41 PM
    Adding a polygon to cover some paths in MapLibre Compose Android As the title states, I'd like to draw a polygon on a Map using MapLibre and JetPack Compose. The polygon should cover some paths to draw like a walking path, but I cannot understand how to properly add a new source to the map. My code up to this point is this: package com.oasi.oasiapp.pathmaps import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import...
  • r

    rss

    09/17/2025, 4:41 PM
    How to send tcp packets to internet I am running a local proxy via Netty on Android. Through Nekobox, the requests are routed to the proxy, and then I forward them to the server. On the server, they are supposed to be sent to the Internet, but no matter what I try, I just get timeouts. The server is written in kotlin. On the server, I receive information like this: server address port payload The payload looks like this: GET / HTTP/1.1 Host: cp.cloudflare.com User-Agent: Go-http-client/1.1 Accept-Encoding: gzip I tried forming...
  • r

    rss

    09/17/2025, 6:41 PM
    EACCES (Permission denied) error when trying to send a file over the Internet An error occurs when attempting to send a file via a Telegram bot. This issue is being debugged on a device with API version 29. The function that performs the sending: fun sendVideoToTelegram( chatId: Long, videoFile: File, caption: String = "") { if (!videoFile.exists() || !videoFile.isFile) { println("Error: Video file does not exist or is not a...
  • r

    rss

    09/18/2025, 12:21 AM
    Should derived fields be sent by the server or regenerated on the client? I’m working on an Android app (Kotlin + Jetpack Compose) that displays information about journeys. The server sends all the raw stop details for a journey, but some values can be derived from this data. For example, suppose I have this data class for stops: data class Stop( val stationCode: String, val arrivalTime: Int, val departureTime: Int val km: Int ) When the server sends me a list of stops, I can compute the journey time like this: val journeyTime =...
  • r

    rss

    09/19/2025, 8:41 AM
    How to test Android app with Entra ID login (Espresso) and verify data saving on server? I am developing an Android app that uses Microsoft Entra ID login for authentication. After a successful login, the app fetches some user data and also allows saving additional data to the server. I want to write automated tests for this flow, but I am facing issues: Since Entra login uses a web view for authentication, Espresso cannot directly interact with it. After login, I need to verify that data is fetched and that saving data to the server works correctly. My Questions: What is the...
  • r

    rss

    09/19/2025, 9:21 AM
    Change cluster icon in Mapbox compose for Android I would like to set a specific icon for my clusters in mapbox but I can't find how to do this in compose. I found some tutorials to do this in classic Java but can't find how to adapt it to the compose sdk. Here is my current implementation @Composable private fun Map() { val context = LocalContext.current val places = getGeoJsonFeatures(context) val mapViewportState = rememberMapViewportState { setCameraOptions { zoom(8.0)...
  • r

    rss

    09/19/2025, 11:41 AM
    Why is my IconButton not updating when I click on it? I'm making a little app to save my collection of records, I have a search bar, a menuBar with three categories and each record has a button to add to collection and one to add to wishlist, I try to update the UI in my ViewModel, the searchBar and the menuBar work but the buttons don't update (empty heart when the record is not in WIshlist and filled heart when it is). data class RecordsAppUiState( val records : Flow, val searchValue : String, val category: Category =...
  • r

    rss

    09/19/2025, 2:01 PM
    How to make Android Studio code completion include all parameters for a function that accepts a trailing lambda? When I write Kotlin code in Android Studio, and I have a method like this:

    https://i.sstatic.net/IY6HHu1W.png▾

    private fun test(a: String, b: Int, c: Int, d: Int, callback: (() -> Unit)) { } But when I type test, Code Completion Popup will appear:

    https://i.sstatic.net/Tp5bd8MJ.png▾

    When I choose the default first one, <a...
  • r

    rss

    09/19/2025, 3:21 PM
    Flutter; AGP, Kotlin and Gradle Issues I am having this error on my console when trying to run; FAILURE: Build failed with an exception. * What went wrong: Execution failed for task 'fluttertoastcompileDebugKotlin'.
    A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
    > Compilation error. See log for more details * Try:
    Run with --stacktrace option to get the stack trace.
    Run with --info or --debug option to get more log output.
    Run...
  • r

    rss

    09/19/2025, 5:21 PM
    How to submit a sponsor transaction using Aptos Kotlin SDK through a Paymaster? I’m trying to submit a sponsored transaction on Aptos using the Kotlin SDK via a Paymaster. I can successfully whitelist the account and get a response from the sponsor gas API, but I’m stuck on constructing a transaction that the Aptos submit transaction API accepts. Here’s the function I use to call the sponsor gas endpoint and extract the fee payer and authenticator: private suspend fun sponsorGas( txnJson: JsonObject ): Pair { val request = Request.Builder()...
  • r

    rss

    09/19/2025, 7:01 PM
    Problem with automatic center in LazyColumn I’ve been learning Kotlin and Jetpack Compose for the past few days, so please bear with me! I’m currently working on an app with movies/anime. Right now, I’m focusing on the main screen of the app. I have an issue: after changing the index in a LazyRow, the LazyRow gets centered vertically on the screen, but I need it to always stay at the bottom so that the YouTubePlayer remains visible. I don’t understand why this happens or what exactly is responsible for centering the element. When...
  • r

    rss

    09/19/2025, 7:41 PM
    How to generate openapi docs offline with spring and kotlin I'm trying to generate apidocs docs in a github pipeline, for a kotlin + spring + springdoc-openapi-starter-webmvc-ui, but I dont want to start the application and serve a localhost uri for openapi generate the docs because it's need connect to database and download some depencies... Its a more work to configure. How to generate apidocs without start the application?
  • r

    rss

    09/20/2025, 5:31 PM
    How can I load a map of objects from YAML using Micronaut's ConfigurationProperties? I'm using the Micronaut framework, and using ConfigurationProperties to load application config into an injectable bean. This has worked well so far, but I'm now stuck on loading nested objects into a Map. This is the config section from my application.yaml. // application.yml company: location: "New York" people: john: title: "Associate" department: "Sales" jane: title: "Manager" department: "Accounting" And this is my Kotlin class //...
  • r

    rss

    09/22/2025, 7:11 AM
    Integration test for a mobile app connected to firebase firestore I have a mobile application built with Kotlin and linked with firebase firestore, I have a 'LoginOnline' method which call Firebase Authentication to check the user credentials. I need to know how to call it in test and assert the result. Here is the login method public fun loginOnline(loginRequestModel: LoginRequestModel) { viewModelScope.launch { authenticationApiRepository.login(loginRequestModel = loginRequestModel).collect { _loginState.value = it }...
  • r

    rss

    09/22/2025, 8:51 AM
    default constructor not found. class xxx (due to FastJSON) Actually this is a solution not a question... Just wonder if this can help ppl (I can't found any solution until now) Version: FastJson: "1.1.76.android_noneautotype kotlin: "2.1.0" Before this, make sure: Data class is implements Serializable added kotlin-reflect dependency Make sure it runnable in non-obfuscation env Now, Solution: make sure all data class is keep in proguard then add this -keep class kotlin.reflect.jvm.internal.KClassImpl {*;} Then hopefully this help you ~
  • r

    rss

    09/22/2025, 10:11 AM
    How to reduce Kotlin/Gradle compile times? We’re struggling with long compile times and unreliable HotSwap in our project. Compiling after even a small code change regularly takes 5–8 minutes, which slows down development. IntelliJ IDEA’s Apply HotSwap feature usually fails. We’d like to either cut compile times drastically or get HotSwap working reliably. But ideally both. Setup: Frameworks: RePlay, jOOQ, Flyway, OpenAPI Laptop: Lenovo, 32 GB RAM with 32 GB Swap Java: Corretto 21 Gradle: 8.5 Kotlin: 2.2.20-RC2 Gradle properties...
  • r

    rss

    09/22/2025, 12:11 PM
    Kotlin slow compile times When we want to compile our project, it regularly takes somewhere between 5-8 minutes. This is an issue for our developers as we want to be able to quickly test our changes. More often than not, the "Apply HotSwap" feature from IntelliJ IDEA also does not work, as it crashes out saying it can't apply the hotswap for a plethora of reasons, none of which have been indicative of why it went wrong so far. We've already scoured the web trying to find solutions and have (attempted to) implement(ed)...
  • r

    rss

    09/22/2025, 8:31 PM
    Invalid device requested composition type change: Device (2) --&gt; Device (2) error with 4x4 grid but not 3x3 I'm encountering a strange error in my Android application when displaying images in a grid layout As a result my screen flickering on bottom part: Invalid device requested composition type change: Device (2) --> Device (2) Problem Details: 3x3 grid with images: Works fine, no errors 4x4 grid with images: Throws the above error Same code, only difference is grid size Questions: What does "composition type change: Device (2) --> Device (2)" mean? Why does this only occur with 4x4 grids and...