Android 与 Kotlin 入门
It’s extremely easy to start using Kotlin for Android development. In this tutorial we’ll follow the warming up process with Android Studio. If you're using Intellij IDEA with Android, the process is almost the same.
Creating a project
First, create a new Kotlin Android Project for your application:
Open Android Studio and click Start a new Android Studio project on the welcome screen or File | New | New project.
Select an activity that defines the behavior of your application. For your first "Hello world" application, select Empty Activity that just shows a screen, and click Next.
In the next dialog, provide the project details:
- name and package
- language: select Kotlin
Leave other options with their default values and click Finish.
Once you complete the steps, Android Studio creates a project. The project already contains all the code and resources for building an application that can run on your Android device or an emulator.
Building and running the application
The process of building and running the Kotlin application in Android Studio is exactly the same as with Java.
To build and run your application on an emulator:
- Run the predefined app configuration by clicking Run on the toolbar or Run | Run 'app'.
Select Create New Virtual Device.
Select a device you like and click Next.
Select a system version and download its image.
Verify the emulator configuration and click Finish.
- Click OK and here it is - your first Kotlin application for Android!
Kotlin有着极小的运行时文件体积：整个库的大小约 964KB（1.3.31 版本）。这意味着 Kotlin 对 apk 文件大小影响微乎其微。
就对比 Kotlin 与 Java所编写的程序而言，Kotlin 编译器所生成的字节码看上去几乎毫无差异。
If you want to customize your builds or run configuration, refer to the Android Studio documentation.