Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not found import kotlinx.coroutines.flow.*

I am trying to learn Kotlin Flow. And when I try to add

import kotlinx.coroutines.flow.* it is not resolving.

Can you please look at my dependencies and help to solve the problem?

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
ext.kotlin_version = '1.3.61'

Please help me to solve the issue.

like image 865
noobEinstien Avatar asked Dec 04 '19 04:12

noobEinstien


People also ask

What is flow in coroutines?

In coroutines, a flow is a type that can emit multiple values sequentially, as opposed to suspend functions that return only a single value. For example, you can use a flow to receive live updates from a database. Flows are built on top of coroutines and can provide multiple values.

How do I add coroutines to Kotlin project?

Go to Tools → Kotlin → Configure Kotlin Plugin Updates, select “Stable” in the Update channel drop-down list, and then click Check for updates. We are adding coroutines-core along with coroutines-android. Now, sync your project with gradle files and you are ready use the latest Coroutines.

What is a kotlin Coroutine?

A coroutine is a concurrency design pattern that you can use on Android to simplify code that executes asynchronously. Coroutines were added to Kotlin in version 1.3 and are based on established concepts from other languages.


Video Answer


2 Answers

From the document. Try to add the below dependence in to the build.gradle file(in the app level):

dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
} 
like image 93
John Le Avatar answered Oct 22 '22 06:10

John Le


The answer from John Le did not work for me, however this worked. Inside your build.gradle.kts (under dependencies) add:

implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.5.2")

You can read more about it here

like image 1
w1cked Avatar answered Oct 22 '22 07:10

w1cked