简体   繁体   中英

Kotlin file to apk android flow?

What is execution flow of Kotlin file to apk in android. Using Java file like this .Java file -> .class file -> classes.dex -> .apk file. Refer this

for more details.

Kotlin can be compiled to java classfile format, so it's: .kt file -> .class file -> classes.dex -> .apk file.

It differs from the Java to APK tool chain only in the first step, I wrote a simple explaination in the format of your given link:

Kotlin compilation

Your code is written in kotlin. But is that kotlin code compiled and run the same way as, say, a web application?

The compilation process for Android apps written in kotlin is very different from other Java applications. But it begins in the same way: your kotlin source code files are compiled into .class files using the kotlinc command (assuming you have installed kotlin and your source file is named activity.kt ):

kotlinc activity.kt

or use other build tool to compile.

This converts kotlin code like this:

class MainActivity(): XXX {
    init {
        currentPosition = 0
    }
}

into Java byte-codes representing Java assembly that looks something like this:

public com.hfad.bitsandpizzas.MainActivity();
  Code:
   0:   aload_0
   1:   invokespecial   #5; //Method android/app/Activity."<init>":()V
   4:   aload_0
   5:   iconst_0
   6:   putfield    #3; //Field currentPosition:I
   9:   return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM