十分钟开始Kotlin的填坑之旅

作者: ZoranLee | 来源:发表于2017-08-06 22:08 被阅读94次

1. Kotlin是什么?为什么选用它?

Kotlin 是一门把 Java 平台作为目标的新的编程语言。

它简洁、安全、优雅而且专注于和 Java 代码间的互操作性。

Kotlin 能够很好的与现有的 Java 库和框架并存。而且,它运行的性能不亚于 Java 。

2.Kotlin在Android中的配置

如果使用android studio 3.0及以上版本的话可以直接忽略本次配置步骤

PS:集成 Kotlin 到现有的安卓应用里面是十分容易的,

只需要使用免费的 Android Studio 的 Kotlin 插件。
  • step1:选择android studio 下的 Preferences选项
image.png
  • step2:在plugins选项中,右侧的文本框中键入Kotlin,然后选择Browse repositories...
image.png
  • step3:选中Kotlin插件,然后install
image.png
  • step4:在工程中的具体配置

      apply plugin: 'kotlin-android'
      compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
      repositories {
       mavenCentral()
      }
    
image.png
  • step5:配上Kotlin的版本信息

    buildscript {
    ext.kotlin_version = '1.1.3-2'
    repositories {
       jcenter()
       maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
       maven {
          url "https://dl.google.com/dl/android/maven2/"
        }
      }
     dependencies {
      classpath 'com.android.tools.build:gradle:2.3.3'
      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
    }
    }
    
    
    
    
    自此基本配置完成就可以开始使用Kotlin开发Android了,而且还可以和JAVA无缝切换
    

相关文章

网友评论

    本文标题:十分钟开始Kotlin的填坑之旅

    本文链接:https://www.haomeiwen.com/subject/ylwrlxtx.html