官术网_书友最值得收藏!

Adding support for coroutines

Now that the project has been created, it's time to add coroutines support. To do this, open the Project section and double-click in build.gradle for the project. It is located inside the Gradle Scripts section:

The correct build.gradle file says Project: RssReader inside parenthesis 

Inside this document, you will add a new variable to centralize the coroutines version. In a new line below ext.kotlin.version, add ext.coroutines_version, as shown here, for example:

buildscript {
ext.kotlin_version = '1.2.50'
ext.coroutines_version = '0.23.3'
...
}
Every time you modify the  build.gradle  files, Android Studio will ask for the configuration to be synchronized again. Until the synchronization is made, the changes will not be applied. 

Now you need to add the dependencies for coroutines. Append the dependency configuration in the build.gradle file for the Module:

The build.gradle file for the Module

First, we will add the dependency for coroutines:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-
jdk7:
$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-
core:
$coroutines_version"
<...>
}

The application can be executed either on an emulator or on a real device from within Android Studio or from the command line. Android Studio's User Guide offers excellent information on how to do this, in their documentation at  https://developer.android.com/studio/run/index.html

Currently, coroutines are considered an experimental feature. In order to remove any warning when compiling or running apps using coroutines, it's necessary to also append this to the build.gradle file for the Module:

kotlin {
experimental {
coroutines "enable"
}
}
Once coroutines are no longer considered experimental, you can safely avoid adding the previous snippet of code.
主站蜘蛛池模板: 扶绥县| 永宁县| 会同县| 郴州市| 甘谷县| 中西区| 古田县| 马鞍山市| 土默特右旗| 应用必备| 玛纳斯县| 孝昌县| 蛟河市| 临泽县| 陕西省| 乾安县| 麻江县| 酒泉市| 永靖县| 乐东| 卓资县| 凤山县| 当雄县| 江永县| 玛多县| 会宁县| 秭归县| 鄂托克旗| 汕尾市| 新和县| 庄河市| 宕昌县| 富裕县| 济南市| 同仁县| 张家界市| 安阳市| 定远县| 尼木县| 仙居县| 杭锦旗|