kotlin

“Unresolved reference: implementation” by using subprojects in kotlin-gradle

你离开我真会死。 提交于 2021-01-02 05:56:06
问题 I want to split my project into subprojects. The default gradle setting from the Intellij IDE is: import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.3.50" } group = "project" version = "0.0.1-SNAPSHOT" repositories { mavenCentral() } dependencies { implementation(kotlin("stdlib-jdk8")) } tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" } That setting compiles. ButI don't want repeat that code in every subproject. So I changed the build

Combine multiple Kotlin flows in a list without waiting for a first value

余生颓废 提交于 2021-01-02 05:47:12
问题 I have a List<Flow<T>> , and would like to generate a Flow<List<T>> . This is almost what combine does - except that combine waits for each and every Flow to emit an initial value, which is not what I want. Take this code for example: val a = flow { repeat(3) { emit("a$it") delay(100) } } val b = flow { repeat(3) { delay(150) emit("b$it") } } val c = flow { delay(400) emit("c") } val flows = listOf(a, b, c) runBlocking { combine(flows) { it.toList() }.collect { println(it) } } With combine

Combine multiple Kotlin flows in a list without waiting for a first value

两盒软妹~` 提交于 2021-01-02 05:46:51
问题 I have a List<Flow<T>> , and would like to generate a Flow<List<T>> . This is almost what combine does - except that combine waits for each and every Flow to emit an initial value, which is not what I want. Take this code for example: val a = flow { repeat(3) { emit("a$it") delay(100) } } val b = flow { repeat(3) { delay(150) emit("b$it") } } val c = flow { delay(400) emit("c") } val flows = listOf(a, b, c) runBlocking { combine(flows) { it.toList() }.collect { println(it) } } With combine

AndroidX Security EncryptedSharedPreferences v1.1.0 /w API 21 issue

筅森魡賤 提交于 2021-01-02 05:42:07
问题 I decided to use new EncryptedSharedPreferences from AndroidX Security library. Since the app is supporting API 21 and higher, I decided to try out this new v1.1.0-alpha02 version, since it supports API 21+ So, I succeded to make the implementation for API 23+, but for older versions where Android KeyStore is not supported, I couldn't make it right, and there are no exact instructions how the master key should be created to make it work somehow. The code for initializing SharedPrefs:

AndroidX Security EncryptedSharedPreferences v1.1.0 /w API 21 issue

牧云@^-^@ 提交于 2021-01-02 05:40:25
问题 I decided to use new EncryptedSharedPreferences from AndroidX Security library. Since the app is supporting API 21 and higher, I decided to try out this new v1.1.0-alpha02 version, since it supports API 21+ So, I succeded to make the implementation for API 23+, but for older versions where Android KeyStore is not supported, I couldn't make it right, and there are no exact instructions how the master key should be created to make it work somehow. The code for initializing SharedPrefs:

Kotlin infinite sequences with iterator function

北慕城南 提交于 2021-01-02 05:29:51
问题 I am confused about how to create an infinite sequence in Kotlin to use for lazy evaluation. In Java: IntStream.iterate(0, i -> i + 2) .limit(100) .forEach(System.out::println); but sequences seem much more confusing then Java streams. The sequence constructor is very confusing the doc for it says: /** * Given an [iterator] function constructs a [Sequence] that returns values through the [Iterator] * provided by that function. * The values are evaluated lazily, and the sequence is potentially

Kotlin - IllegalArgumentException in overridden method

不羁的心 提交于 2021-01-02 05:20:41
问题 In Kotlin I'm overriding this two Google Sign-In functions: override fun onConnectionFailed(result: ConnectionResult) { if (result.hasResolution()) { try { result.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE) } catch (e: IntentSender.SendIntentException) { // Unable to resolve, message user appropriately } } else { val gaa = GoogleApiAvailability.getInstance() gaa.getErrorDialog(this, result.errorCode, 0) } } override fun onActivityResult(requestCode: Int, resultCode: Int,

Kotlin - IllegalArgumentException in overridden method

这一生的挚爱 提交于 2021-01-02 05:20:16
问题 In Kotlin I'm overriding this two Google Sign-In functions: override fun onConnectionFailed(result: ConnectionResult) { if (result.hasResolution()) { try { result.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE) } catch (e: IntentSender.SendIntentException) { // Unable to resolve, message user appropriately } } else { val gaa = GoogleApiAvailability.getInstance() gaa.getErrorDialog(this, result.errorCode, 0) } } override fun onActivityResult(requestCode: Int, resultCode: Int,

Unfortunately MyApp has stopped. How can I solve this?

跟風遠走 提交于 2021-01-02 04:04:41
问题 I am developing an application, and everytime I run it, I get the message: Unfortunately, MyApp has stopped. What can I do to solve this? About this question - obviously inspired by What is a stack trace, and how can I use it to debug my application errors?, there are lots of questions stating that their application has crashed, without any further detail. This question aims to instruct novice Android programmers on how to try and fix their problems themselves, or ask the right questions. 回答1

Can an integer in Kotlin be equal to an math expression?

岁酱吖の 提交于 2021-01-01 09:25:35
问题 I am making a program that solves a math expression, for example, 2+2. Can I set an integer equal to something like this: val input = "2+2" input.toInt() 回答1: Kotlin doesn't have any built in ways for evaluating arbitrary expressions. The toInt function can only parse a String containing a single whole number (it's just a wrapper for Integer.parseInt). If you need this functionality, you'll have to parse and evaluate the expression yourself. This problem is no different than having to do it