简体   繁体   English

Android Studio是否支持所有Kotlin功能和API?

[英]Does Android Studio support all Kotlin features and APIs?

I am an Android Developer and have a general Kotlin question. 我是一名Android开发人员,对Kotlin有一个一般性的问题。 Does Android Studio support all Kotlin features and APIs? Android Studio是否支持所有Kotlin功能和API? I am certain that all basic types and operators are fully supported and Android Studio can compile. 我敢肯定,所有基本类型和运算符均得到完全支持,并且Android Studio可以编译。 Is it safe to also assume that Functions, Lambdas, Coroutines, etc. are fully supported? 是否可以安全地假设完全支持Function,Lambda,Coroutines等? For example, when Java 8 support was announced for Android Studio, there was a documentation website explaining which Java 8 features were supported and which were not: 例如,当宣布对Android Studio的Java 8支持时,有一个文档网站说明了支持哪些Java 8功能,而哪些不支持:

https://developer.android.com/studio/write/java8-support#supported_features https://developer.android.com/studio/write/java8-support#supported_features

But this does not exist for Kotlin. 但这对于Kotlin不存在。 I'm assuming if it's a line of standard Kotlin code, it will compile in Android Studio, is that correct? 我假设它是一行标准的Kotlin代码,它将在Android Studio中编译,对吗?

The reason for my question is that I work with a group of Java server (mostly spring boot) and JavaFX developers, and we like to share as much code as possible. 我提出这个问题的原因是,我与一组Java服务器(主要是春季启动)和JavaFX开发人员一起工作,我们希望共享尽可能多的代码。 The lack of Java 8 compatibility in Android caused some problems for us. Android中缺乏Java 8兼容性为我们带来了一些问题。 We're looking to convert most of our code into Kotlin now. 我们正在寻求将大多数代码转换为Kotlin。 I'd like to assume that all of the standard features: 我想假设所有标准功能:

https://kotlinlang.org/api/latest/jvm/stdlib/index.html https://kotlinlang.org/api/latest/jvm/stdlib/index.html

And hopefully all of the coroutines features: 并希望所有协程功能:

https://kotlinlang.org/docs/reference/coroutines/coroutines-guide.html https://kotlinlang.org/docs/reference/coroutines/coroutines-guide.html

Will be fully supported for both let's say an Android app built with Android Studio and a Java desktop app built with IntelliJ. 假设使用Android Studio构建的Android应用程序和使用IntelliJ构建的Java桌面应用程序都将得到完全支持。

Within reason, you control the version of Kotlin that gets used and therefore what features are available. 在一定程度上,您可以控制所使用的Kotlin的版本以及可用的功能。

If you have a Kotlin-enabled Android Studio project, and you look in the top-level build.gradle file, you may see code like this: 如果您具有启用了Kotlin的Android Studio项目,并且在顶级build.gradle文件中查找,则可能会看到类似以下的代码:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  ext.kotlin_version = '1.3.20'
  repositories {
    google()
    jcenter()

  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    google()
    jcenter()

  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

ext.kotlin_version = '1.3.20' controls the Kotlin version that you will use for the Kotlin plugin (via the interpolated string in the classpath directive), and similarly for the Kotlin runtime dependency in a module's build.gradle file. ext.kotlin_version = '1.3.20'控制将用于Kotlin插件的Kotlin版本(通过classpath指令中的插值字符串),以及类似地用于模块build.gradle文件中的Kotlin运行时依赖build.gradle

So, a project with the above code can use Kotlin/JVM features that were supported in Kotlin 1.3.20. 因此,具有上述代码的项目可以使用Kotlin 1.3.20支持的Kotlin / JVM功能。

The runtime dependency that we use today is org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version . 我们今天使用的运行时依赖项是org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version The jdk7 indicates that the runtime does not depend on any Java 8+ stuff that Android lacks. jdk7表示运行时不依赖于Android缺少的任何Java 8+。

However, changes in future versions of Kotlin will require you to upgrade the Kotlin version in your project. 但是,将来Kotlin版本的更改将要求您升级项目中的Kotlin版本。 For example, a project using 1.2.71 might not have access to all Kotlin 1.3 syntax. 例如,使用1.2.71的项目可能无法访问所有Kotlin 1.3语法。

Kotlin is fully supported by Android and Android Studio and even advertised on the Android website: Android和Android Studio完全支持Kotlin,甚至在Android网站上发布了广告:

Kotlin is production-ready for your Android app development. Kotlin已为您的Android应用程序开发做好了生产准备。

Source 资源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio 是否支持 Kotlin 方法断点? - Does Android Studio support Kotlin method breakpoints? Android Studio AppCompat不支持当前的主题功能 - Android Studio AppCompat does not support the current theme features Android Studio 3 是否支持 Java 9 进行 Android 开发? 如果是,则支持 Java 9 的哪些功能? - Does Android Studio 3 support Java 9 for Android development? If so, what features of Java 9 are supported? NDK支持是一项实验性功能,Android Studio中尚未支持所有用例错误? - NDK support is an experimental features and all use cases are not yet supported error in Android Studio? 升级到Android Studio 3.0 Canary 5导致“IllegalArgumentException:AppCompat不支持当前主题功能..” - upgrading to Android Studio 3.0 Canary 5 causing “IllegalArgumentException: AppCompat does not support the current theme features..” AppCompat不支持当前的主题功能,Android吗? - AppCompat does not support the current theme features, android? Android Studio当前不支持使用支持库RenderScript API? - Use of Support Library RenderScript APIs is not currently supported with Android Studio? Android Studio是否支持Maven? - Does Android Studio support Maven? 适用于 Android 的 Google Duo 应用程序支持哪些意图或 API? - what intents or apis does Google's Duo app for Android support? android是否支持用于实现RTP的API,用于VoIP和PTT项目的RTSP? - Does android support APIs for implementing RTP,RTSP for VoIP and PTT Project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM