Introduction to Kotlin and Android Development Kotlin & Architecture Overview
Transcript from the "Kotlin & Architecture Overview" Lesson
>> So, that's up to the basics of the Android operating system and the architecture of our apps. But let's jump directly into Kotlin code. So Kotlin, it's a language created by JetBrains. I'm not sure if you have heard about JetBrains. JetBrains is a company that originally was building IDEs.
[00:00:47] And by the way, Android Studio is by JetBrains as well. It's an IDE built by JetBrains, that Google license to JetBrains so we can use it for free. But actually Android Studio is a JetBrains IDE that we can get for free. So Kotlin the language was also created by JetBrains.
[00:01:10] It's open source and that's why Google or the Android team has decided to use it on Android, why? Because originally the SDK was only available with Java. And actually the SDK is stacked with Java 6 and some things, some Java 8. Not even Java 8 completely. So it was an old version of Java.
[00:01:36] And it was actually complicate to actually evolve Java for Android mostly with a legal fight between Oracle and Google. So that's why the Android team decided to have an alternative that is modern and faster, that is compatible with Java virtual machine Android, and that's Kotlin. It's an statically typed language.
[00:02:26] It's multi-platform. We are going to support only today Kotlin for Android. But actually Kotlin also compiled to Java virtue machine for back end. So Java Enterprise. Or Kotlin, can also compile into other platforms, even the web. I will get into that in a minute. It's easy to learn.
[00:03:13] So it has less ceremonial compared to Java. I mean on Java you need to create listeners and for listeners, you need to create anonymous classes with the listener new side, shot for an on click handler. With this the idea is to be less ceremonial with less bureaucracy. Okay, let's go and jump directly into code that looks nice.
[00:03:36] It has some modern ideas in terms of what we can do. Here we have a big warning. Kotlin include a lot of smart ideas that sometimes are not available for Android app development. So you will find, not today but later when we get with more Kotlin app development, you can get into some architectural ideas, some changes that are not working on Android, why?
[00:04:04] Because on Android we have a constraint. That's the Java built on machine or the executable built on machine. They call it Android run time. And yeah, we are not changing that run time, okay? So there are some limitations on the run time that when you're building Kotlin for other platforms you don't have.
[00:04:24] It includes null safety, the same as other modern languages such as Dart or Swift. And we'll get into that in a minute. We have interpreted languages, where we ship source code, intermediate language, where we ship bytecode when we compile. And compiled languages that we're going to ship machine code.
[00:04:45] You can see Kotlin, it's actually compatible with Bytecode and Machine Code. So with Kotlin we can actually build libraries of code or apps that are for instance, a 64 bit or for ARM. So we can actually ship binary code. But for Android, we will focus only here, on bytecode.
[00:05:09] Because we are going to create code that will work in the Android SDK, in the Android run time, okay? But have in mind that coding is available for other platforms. So Koltlin can compile to JVM version 6, to JVM version 8, to Android Java DEX executable, that's the one that we are going to use.
[00:05:55] In this case when we are talking about Native in Android, so what's the difference between this Android and the other Android? Is that, that's actually for libraries, not for working with the user interface. I mean you have a cryptographic library or a database library, you can build that in native Kotlin it ships as a native library that is more performant than the intermediate language that's the BM.
[00:06:19] And also multi platform, so you can actually share the same database that you have just created with iOS or Mac OS or Windows. And just to finish this introduction to the Kotli idea, there is something that they want you to know that exists and is not what we are going to use today.
[00:06:38] It's called, Kotlin Multiplatform Mobile, KMM. Kotlin Multiplatform Mobile is another framework that lets you use Kotlin to create libraries that you can use them on Android and iOS. Not user interface, not user interfaces, just libraries. So your business law shake, you can be your models, your view models.
[00:07:06] You can build that in Kotlin and then use that in a normal Kotlin Android project or in a Swift project on iOS. That's known as Kotlin Multiplatform Mobile. We are close to see some code but before doing that let me show you this diagram really quickly. So this is the current Android app development ecosystem.
[00:07:29] You have Kotlin Java code that can use Android jetpack libraries and those libraries can actually talk to your Android SDK. So we are going to write Kotlin code. So our Kotlin code can use Jetpack and also can use directly the API's from the SDK. Also you can write your own C++ code and connect them through something known a Java Native Interface.
[00:08:01] It doesn't matter. So, this is the ecosystem. What we're going to write is just Kotlin and maybe C++, not today but on another project you can also write C++. Today we're going to just write Kotlin. The rest is just part of the build, or part of the operating system, is not our code, okay?
[00:08:24] And our code will just be Kotlin today from that ecosystem. Just have in mind that that code can talk to C++, they can talk to Jetpack libraries and also they can talk to the Android SDK APIs. So if you wanna use Bluetooth API, while that's part of the Android SDK, you can talk to that API.
[00:08:44] And in the APK file, so when you're building the app, it will go DEX code, DEX is Dalvik executable. Oops, so DEX is Dalvik executable. And also Jetpack; because Jetpack is not part of the operating system. Jetpack is a library that we are deciding to use. Its from the Android team so it's kind of an official library but it's still a library.
[00:09:10] So that means that in your APK, the the compiled code of Jetpack will also be shipped In the package. And if you have C++ code, you will have the libraries combined. So we have a question on installing Android Studio and problems with one of the utilities, that's called HAXM.
[00:09:33] So that's actually an emulator, let's say improver, so it's a tool that will improve the performance of your innovator on Intel processor. If you have problems in styling, you need to read the methods that you have, typically have to do or your computer is not Intel compatible for VM acceleration.
[00:09:54] And sometimes you need to get into the BIOs of your computer and enable a built on function. So if that tool is not working it shouldn't be a big deal, the only problem is that your emulator will work slower because it's not running directly into your CPU. The emulator is IBM, so it's actually will convert To Intel and it's actually slower.