[JAVA] Introduction to kotlin for iOS developers ②-Project creation

Try to actually make a project

The environment for using kotlin was set up last time. Next, let's actually create a project.

Contrast with Xcode

When you start Android Studio, a window similar to the "welcome screen" in Xcode opens. ・ Android Studio スクリーンショット 2017-03-08 3.01.13.png ・ Xcode スクリーンショット 2017-03-08 3.07.00.png At first there is no project, so click "Start a new Android Studio project". スクリーンショット 2017-03-08 3.01.33.png First, decide on a name for the entire project. Unless otherwise specified, "My Application" entered by default is OK.

スクリーンショット 2017-03-08 3.01.48.png Enter the environment in which the next application to be created will run. Basically, there is no problem with "Phone and Tablet" (if you want to make something that works in other environments, please select it appropriately). Then select the Android version. As of March 2017, Ice Cream Sandwich (version 4.0) is selected as standard.

Android version (slightly derailed)

Unlike iOS, Android needs to support multiple versions. In the case of iOS, basically you can use the latest version on any device (about 4S has been cut recently), and even if it is old, there is no problem if you go back about 2 generations, but Android is for each device. You need to be aware that the available versions are limited and there are always so many versions. Currently, the latest Android is Nougat (version 7.0), but considering the models currently on the market, it is safe to make it compatible with IceCream Sandwich (version 4.0).

Continue (quiet talk break)

Select the target device and select "Next". スクリーンショット 2017-03-08 3.02.07.png

This screen is in Xcode

スクリーンショット 2017-03-08 3.07.43.png This is the corresponding part.

There are various templates available, but it's okay if you choose "Empty Activity".

スクリーンショット 2017-03-08 3.02.25.png Finally, give a name to the layout file that corresponds to Activity (like ViewController in Xcode) and the project is complete.

point

I would like you to look at this screen a little carefully, but the standard input is Activity Name is "Main Activity" and Layout Name is "activity_main". This is actually quite important, but on Android, one screen is composed of two types: "XML layout file that displays the screen" and "Activity file by Java (kotlin) that sets the movement of the screen". It's the same feeling as putting a view controller on the storyboard in Xcode and making the swift file correspond to it, but in Xcode you can set it on the storyboard, but in Android Studio you have to write it in the code, so you have to write it yourself You have to be aware that "this is the XML that corresponds to this Java". Therefore, there are basically no rules for file naming, but the tacit understanding is that "Java and XML names correspond".

To finish

As usual, it's only kotlin operation from here, so thank you for saying "It's okay to write in Java". Actually, a Java file is created in a new project, so you have to rewrite it to kotlin. スクリーンショット 2017-03-08 3.04.01.png

If you open the Main Activity you created earlier from the navigation on the left, you will see the screen above. After confirming that Main Activity is selected on the tab, open the Code above and press "Convert Java File to Kotlin File" added at the bottom. Then a pop-up will appear and wait for a while.

スクリーンショット 2017-03-08 3.04.32.png

The tab icon スクリーンショット 2017-03-08 3.05.17.png From スクリーンショット 2017-03-08 3.05.03.png When it changes like this, the conversion is complete. At the bottom right of the icon is a small K pattern, which is the kotlin logo. The extension has also changed from ".java" to ".kt". Please note that if you forget this operation, Kotlin will be written in the Java file and an error will occur. スクリーンショット 2017-03-08 3.05.47.png If you click with two fingers on the left navigation bar, the above screen will open. If you select "New", you can select the type of file to add. You can choose from various options, but basically you will use the third "kotlin Activity" from the top. If you select this, kotlin files and XML files will be added at the same time, which is relatively convenient.

Up to here for this time. Next, I will write about "Gradle", which is important for making Android.

Please also include other articles

Introduction to kotlin for iOS developers ①-Environment construction Introduction to kotlin for iOS developers ②-Project creation Introduction to kotlin for iOS developers ③-About gradle Introduction to kotlin for iOS developers ④-Type [Introduction to kotlin for iOS developers ⑤-Practical XML] (http://qiita.com/parappa1002/items/867c5b30055312e74fdb) [Introduction to kotlin for iOS developers ⑥-kotlin creation] (http://qiita.com/parappa1002/items/9f898feb4f83e672b384)

Recommended Posts

Introduction to kotlin for iOS developers ②-Project creation
Introduction to kotlin for iOS developers ⑥-Kotlin creation
Introduction to kotlin for iOS developers ④-Type
Introduction to kotlin for iOS developers ⑤-Practical XML
Introduction to kotlin for iOS developers ③-About gradle
Introduction to kotlin for iOS developers ①-Environment construction
Kotlin Class to send to Java developers
To switch JVM for each project
Introduction to Programming for College Students: Introduction
Generics of Kotlin for Java developers
Kotlin Class part.2 to send to Java developers
Introduction to java for the first time # 2
Introduction to Programming for College Students: Variables
Kotlin scope functions to send to Java developers
Interoperability tips with Kotlin for Java developers
Memo for migration from java to kotlin
Kotlin functions and lambdas to send to Java developers
Introduction to Ratpack (Extra Edition) --Ratpack written in Kotlin
Introduce Kotlin to your existing Java Maven Project
Initial settings for rewriting Java projects to Kotlin
Getting started with Kotlin to send to Java developers
An introduction to Groovy for tedious Java engineers
[Introduction to Java] Basics of java arithmetic (for beginners)
Introduction to Ruby 2
Introduction to SWING
Introduction to web3j
Introduction to Micronaut 1 ~ Introduction ~
[Java] Introduction to Java
Introduction to java
Introduction to Doma
From the introduction of devise to the creation of the users table
Introduction to programming for college students (updated from time to time)
[Spring Boot] How to create a project (for beginners)
[Practice! ] Introduction of JFrame (explaining up to screen creation)
Introduction to Java for beginners Basic knowledge of Java language ①
Introduction to Programming for College Students: Making a Canvas
How to study kotlin for the first time ~ Part 2 ~
How to study kotlin for the first time ~ Part 1 ~