Check out a free preview of the full Introduction to Kotlin and Android Development course
The "Kotlin Q&A" Lesson is part of the full, Introduction to Kotlin and Android Development course featured in this preview video. Here's what you'd learn in this lesson:
Maximiliano answers student questions regarding SDKs compiling to Android and what the function of the triple double quotes are.
Transcript from the "Kotlin Q&A" Lesson
[00:00:00]
>> Do you have any question at this point?
>> I'm kinda a little bit lost on SDKs and compiling to Android. I can't remember what slide it was off of.
>> Let's see, so we were here. This. So we are actually building for Android Java DEX. So that means that this is our target, when we are going to create Android applications, okay, with Kotlin.
[00:00:31]
So we are kind of constrained by that framework, that runtime. But if you do Kotlin for any of the other targets, you don't have those restrictions. Does that make sense? So Kotlin is like a second layer on top of Java for Android. It's not getting rid of Java, it's sitting on top of Java.
[00:01:00]
So actually everything we do in Kotlin will actually need to be compiled into some kind of a Java intermediate language that is called Dalvik Executable. So we are restricted by what that platform can offer.
>> And when we're compiling to what you're saying native Android, can you clear that up for me?
[00:01:18]
>> Yeah, if you compile to native Android, actually you cannot talk to the SDK. Let me me show you. Going back to a previous slide, when we were talking about the Android architecture, Where are you? Nope, it wasn't a previous slide, it was here. So if you're compiling to Android native, you're actually compiling to the NDK, the pink one to the right, not to the normal SDK.
[00:01:51]
Which means that when you are doing that, if you look at the arrows, the pink is talking directly to Native Libraries, not to the Android SDK and UI toolkits. Which means you cannot make your UI, unless you wanna render your UI manually with lines and circles or on the screen.
[00:02:11]
If you wanna use the button and actually the components from the SDK, you must compile Kotlin code for the Android Runtime. If you go Kotlin native with the NDK, you can only talk to the native libraries of the OS, and that's not including the UI toolkit. So meaning that, we will focus here, Okay, on the Android Java DEX, at least when we are working in app.
[00:02:48]
You can still use Kotlin for native, okay, but that means it's not the UI part. It's other parts of your app that can be business logic libraries, again, talking about encoding, decoders. I mean, if you're doing a Netflix application, you want the decoder, the video decoder, well, that can be done in Kotlin with a native library that is faster and also multi platform.
[00:03:14]
So you can actually compile to iOS as well, and to Windows as well, and then you write once, deliver that library everywhere.
>> Thank you.
>> Okay, but for the app, if you wanna use the UI toolkit, we must use Java DEX.
>> Someone in the chat wanted to know if you could review what triple quotes helps you with.
[00:03:34]
>> Simple quote?
>> Triple double quotes, okay, sure. So triple double quotes, it's actually being used for multi line strings. So that means that you can put new lines here, okay, and everything is a string, Okay, you can still use dollar sign to create an expression, so that's also possible, but within multi line.
[00:04:03]
Okay, you can write HTML like this in Kotlin quickly in just multi lines. Without this technique you need to use close the line, concatenate with another string, another string. So triple double quotes will let you make multi line strings.
>> And quotes work within that?
>> Yeah, and single, double quotes will work without, I don't need to escape them.
[00:04:30]
I don't need to do this. So that's why I will say that for JSON or for HTML, it's actually useful if you wanna write HTML here, like I have a paragraph with class, myparagraph. So it just works, I don't need to escape quotes because it will wait for the triple double quotes.
[00:04:51]
This trimIndent will actually remove in the final string all these spaces. If you don't want it, you can just. This was created by the IDE by default, I don't need that. But when you use triple quotes, enter, it automatically adds that because typically we don't want those initial tabs in the final string.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops