Foreword
Kotlin has been out for some time, in fact, I still prefer java, but as a qualified Android developers do not understand kotlin is certainly justified. (Mainly interviews are always asking) so I decided to take a moment to look into their own record from entry to give up, to be honest do not like those high-level language, simply means that there will be a high degree of encapsulation, so that know not why the feeling is very painful, but after all, is Google's own son so the future is likely to be a trend in the development of Android, following a brief look at the process of creating kotlin of recording.
Creating a Kotlin project
Since it is Google's own son, AndroidStudio must be fully supported, if you look at the AndroidStudio version 3.0 can upgrade it, if it is time to create more than 3.0 application you will find:
Select the Include Kotlin support can be
if you are first created Kotlin project would be very slow, patient and wait for your kotlin project to complete half of it!
But when the general download plug-ins will then add the following network problems at the warehouse in the outermost bulid.gradle:
maven { url “http://dpapi.irs01.com:8081/nexus/content/groups/public/” }
maven { url ‘http://192.168.70.2:8081/repository/maven-releases/’ }
Specific location as shown:
first download kotlin plug when there will be the problem, is not required to create the future together with this warehouse.
In this case you will see a screen like this:
and java created when first glance I quite like.
To not worry hello World! After a look at how to create a contrast kotlin files and create Kotlin project before the project after what changes.
Create a file Kotlin
Creating also relatively simple to
select the files in the directory will be selected New Kotlin File / Class and
Default File can be.
Even here is to create a complete AndroidStudio Kotlin project. A look at what has changed in build.gradle:
seeing where the red line will find that in fact two different places:
- At the beginning of the addition of two plug-ins can be simply understood as a declaration using kotlin
- Statement Kotlin compiler plug-in library of
attentive friends will find out that there's a anko library and associated Kotlin, speaking here later this powerful anko library.
The java code into kotlin
If you have java code in your project, and now you want a unified style how to do? Do not worry do not have to manually rewrite the java code. Android studio is to support transformation:
Select the top title bar Code: Then:
When you select the last item you will be surprised to find that your java code becomes:
kotlin the style.
Mixed-use development
If you say to kotlin not familiar with some complex pages or want java to achieve this is OK because every time you create a new Activity time will have the following options:
So you can easily switch java and Kotlin!
to sum up
Android Studio here how to create Kotlin project as well as some common operations to finish it, later would write a series of articles to record their own learning process kotlin, interested small partners together can Ha!