Kotlin bytecode in Android Apps










1















I'm a kotlin and Java developer, and recently I started analyzing the bytecode generated by kotlin. And I found out a lot of wrapper code and other stuff that the compiler generates in order to translate what I have coded in Kotlin to Java.



So, my question is:



Imagine that I have an app that its code is 100% written in kotlin. Dependencies and the main app. All Kotlin.



  1. Does this mean that a different compiler will be used in order to avoid Java compatible bytecode?

  2. Or is there any optimization done by the compiler in this kind of scenarios?

Many Thanks.




I know about Kotlin Native but I think it will only be applied to Android in the future.










share|improve this question
























  • What do you mean by in order to avoid bytecode?

    – leonardkraemer
    Nov 13 '18 at 15:57











  • kotlin has its own compiler, yes

    – Tim Castelijns
    Nov 13 '18 at 16:00











  • @TimCastelijns but it still becomes Java bytecode, although it's an absolute mess.

    – TheWanderer
    Nov 13 '18 at 16:01






  • 1





    What leads you to say "an absolute mess?" It's not.

    – yole
    Nov 13 '18 at 16:05












  • @yole Well I guess I don't know about the bytecode, but when it's decompiled, using Android Studio's decompiler, JADx or APKTool (Java, Java, Smali), it's much harder to follow the code vs a Java app. Kotlin classes also still use kotlin.String, kotlin.Int and kotlin.Unit types when compiled, instead of java.lang.String, int and void.

    – TheWanderer
    Nov 13 '18 at 16:07
















1















I'm a kotlin and Java developer, and recently I started analyzing the bytecode generated by kotlin. And I found out a lot of wrapper code and other stuff that the compiler generates in order to translate what I have coded in Kotlin to Java.



So, my question is:



Imagine that I have an app that its code is 100% written in kotlin. Dependencies and the main app. All Kotlin.



  1. Does this mean that a different compiler will be used in order to avoid Java compatible bytecode?

  2. Or is there any optimization done by the compiler in this kind of scenarios?

Many Thanks.




I know about Kotlin Native but I think it will only be applied to Android in the future.










share|improve this question
























  • What do you mean by in order to avoid bytecode?

    – leonardkraemer
    Nov 13 '18 at 15:57











  • kotlin has its own compiler, yes

    – Tim Castelijns
    Nov 13 '18 at 16:00











  • @TimCastelijns but it still becomes Java bytecode, although it's an absolute mess.

    – TheWanderer
    Nov 13 '18 at 16:01






  • 1





    What leads you to say "an absolute mess?" It's not.

    – yole
    Nov 13 '18 at 16:05












  • @yole Well I guess I don't know about the bytecode, but when it's decompiled, using Android Studio's decompiler, JADx or APKTool (Java, Java, Smali), it's much harder to follow the code vs a Java app. Kotlin classes also still use kotlin.String, kotlin.Int and kotlin.Unit types when compiled, instead of java.lang.String, int and void.

    – TheWanderer
    Nov 13 '18 at 16:07














1












1








1








I'm a kotlin and Java developer, and recently I started analyzing the bytecode generated by kotlin. And I found out a lot of wrapper code and other stuff that the compiler generates in order to translate what I have coded in Kotlin to Java.



So, my question is:



Imagine that I have an app that its code is 100% written in kotlin. Dependencies and the main app. All Kotlin.



  1. Does this mean that a different compiler will be used in order to avoid Java compatible bytecode?

  2. Or is there any optimization done by the compiler in this kind of scenarios?

Many Thanks.




I know about Kotlin Native but I think it will only be applied to Android in the future.










share|improve this question
















I'm a kotlin and Java developer, and recently I started analyzing the bytecode generated by kotlin. And I found out a lot of wrapper code and other stuff that the compiler generates in order to translate what I have coded in Kotlin to Java.



So, my question is:



Imagine that I have an app that its code is 100% written in kotlin. Dependencies and the main app. All Kotlin.



  1. Does this mean that a different compiler will be used in order to avoid Java compatible bytecode?

  2. Or is there any optimization done by the compiler in this kind of scenarios?

Many Thanks.




I know about Kotlin Native but I think it will only be applied to Android in the future.







android kotlin decompiler






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 16:14







André Sousa

















asked Nov 13 '18 at 15:54









André SousaAndré Sousa

1,1581818




1,1581818












  • What do you mean by in order to avoid bytecode?

    – leonardkraemer
    Nov 13 '18 at 15:57











  • kotlin has its own compiler, yes

    – Tim Castelijns
    Nov 13 '18 at 16:00











  • @TimCastelijns but it still becomes Java bytecode, although it's an absolute mess.

    – TheWanderer
    Nov 13 '18 at 16:01






  • 1





    What leads you to say "an absolute mess?" It's not.

    – yole
    Nov 13 '18 at 16:05












  • @yole Well I guess I don't know about the bytecode, but when it's decompiled, using Android Studio's decompiler, JADx or APKTool (Java, Java, Smali), it's much harder to follow the code vs a Java app. Kotlin classes also still use kotlin.String, kotlin.Int and kotlin.Unit types when compiled, instead of java.lang.String, int and void.

    – TheWanderer
    Nov 13 '18 at 16:07


















  • What do you mean by in order to avoid bytecode?

    – leonardkraemer
    Nov 13 '18 at 15:57











  • kotlin has its own compiler, yes

    – Tim Castelijns
    Nov 13 '18 at 16:00











  • @TimCastelijns but it still becomes Java bytecode, although it's an absolute mess.

    – TheWanderer
    Nov 13 '18 at 16:01






  • 1





    What leads you to say "an absolute mess?" It's not.

    – yole
    Nov 13 '18 at 16:05












  • @yole Well I guess I don't know about the bytecode, but when it's decompiled, using Android Studio's decompiler, JADx or APKTool (Java, Java, Smali), it's much harder to follow the code vs a Java app. Kotlin classes also still use kotlin.String, kotlin.Int and kotlin.Unit types when compiled, instead of java.lang.String, int and void.

    – TheWanderer
    Nov 13 '18 at 16:07

















What do you mean by in order to avoid bytecode?

– leonardkraemer
Nov 13 '18 at 15:57





What do you mean by in order to avoid bytecode?

– leonardkraemer
Nov 13 '18 at 15:57













kotlin has its own compiler, yes

– Tim Castelijns
Nov 13 '18 at 16:00





kotlin has its own compiler, yes

– Tim Castelijns
Nov 13 '18 at 16:00













@TimCastelijns but it still becomes Java bytecode, although it's an absolute mess.

– TheWanderer
Nov 13 '18 at 16:01





@TimCastelijns but it still becomes Java bytecode, although it's an absolute mess.

– TheWanderer
Nov 13 '18 at 16:01




1




1





What leads you to say "an absolute mess?" It's not.

– yole
Nov 13 '18 at 16:05






What leads you to say "an absolute mess?" It's not.

– yole
Nov 13 '18 at 16:05














@yole Well I guess I don't know about the bytecode, but when it's decompiled, using Android Studio's decompiler, JADx or APKTool (Java, Java, Smali), it's much harder to follow the code vs a Java app. Kotlin classes also still use kotlin.String, kotlin.Int and kotlin.Unit types when compiled, instead of java.lang.String, int and void.

– TheWanderer
Nov 13 '18 at 16:07






@yole Well I guess I don't know about the bytecode, but when it's decompiled, using Android Studio's decompiler, JADx or APKTool (Java, Java, Smali), it's much harder to follow the code vs a Java app. Kotlin classes also still use kotlin.String, kotlin.Int and kotlin.Unit types when compiled, instead of java.lang.String, int and void.

– TheWanderer
Nov 13 '18 at 16:07













1 Answer
1






active

oldest

votes


















4














The only way you're going to avoid Java bytecode with Kotlin is to use Kotlin Native, and you won't be able to use the Android SDK in that case.



Kotlin JVM, as the name implies, compiles to JVM bytecode; it's one of the main draws of using it. If it compiled to something different, it would be Kotlin Native.



To answer your bullets:



  1. No, the same compiler is used whether or not you have Java source files.

  2. Probably not. Kotlin JVM is made to be almost completely interoperable with Java, and that's the same whether or not your project includes Java code.

Think about if you were creating an Android library in Kotlin. Would you really want it to automatically compile to something other than Java bytecode in that case? It wouldn't be able to be used in Java projects, defeating one of the main reasons Kotlin is so good as a Java alternative.



Also remember, you're using the Android SDK. Even if you have no dependencies in your build.gradle, you still reference the core SDK itself, which is Java. The SDK isn't included in your APK, but it's still used during compilation.



If you want something that avoids Java bytecode, use something like Flutter. It has its own SDK, and can bridge back to Java components. Of course, you can't completely avoid the JVM, because you still need some way for Android to install and open the app.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284773%2fkotlin-bytecode-in-android-apps%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    The only way you're going to avoid Java bytecode with Kotlin is to use Kotlin Native, and you won't be able to use the Android SDK in that case.



    Kotlin JVM, as the name implies, compiles to JVM bytecode; it's one of the main draws of using it. If it compiled to something different, it would be Kotlin Native.



    To answer your bullets:



    1. No, the same compiler is used whether or not you have Java source files.

    2. Probably not. Kotlin JVM is made to be almost completely interoperable with Java, and that's the same whether or not your project includes Java code.

    Think about if you were creating an Android library in Kotlin. Would you really want it to automatically compile to something other than Java bytecode in that case? It wouldn't be able to be used in Java projects, defeating one of the main reasons Kotlin is so good as a Java alternative.



    Also remember, you're using the Android SDK. Even if you have no dependencies in your build.gradle, you still reference the core SDK itself, which is Java. The SDK isn't included in your APK, but it's still used during compilation.



    If you want something that avoids Java bytecode, use something like Flutter. It has its own SDK, and can bridge back to Java components. Of course, you can't completely avoid the JVM, because you still need some way for Android to install and open the app.






    share|improve this answer



























      4














      The only way you're going to avoid Java bytecode with Kotlin is to use Kotlin Native, and you won't be able to use the Android SDK in that case.



      Kotlin JVM, as the name implies, compiles to JVM bytecode; it's one of the main draws of using it. If it compiled to something different, it would be Kotlin Native.



      To answer your bullets:



      1. No, the same compiler is used whether or not you have Java source files.

      2. Probably not. Kotlin JVM is made to be almost completely interoperable with Java, and that's the same whether or not your project includes Java code.

      Think about if you were creating an Android library in Kotlin. Would you really want it to automatically compile to something other than Java bytecode in that case? It wouldn't be able to be used in Java projects, defeating one of the main reasons Kotlin is so good as a Java alternative.



      Also remember, you're using the Android SDK. Even if you have no dependencies in your build.gradle, you still reference the core SDK itself, which is Java. The SDK isn't included in your APK, but it's still used during compilation.



      If you want something that avoids Java bytecode, use something like Flutter. It has its own SDK, and can bridge back to Java components. Of course, you can't completely avoid the JVM, because you still need some way for Android to install and open the app.






      share|improve this answer

























        4












        4








        4







        The only way you're going to avoid Java bytecode with Kotlin is to use Kotlin Native, and you won't be able to use the Android SDK in that case.



        Kotlin JVM, as the name implies, compiles to JVM bytecode; it's one of the main draws of using it. If it compiled to something different, it would be Kotlin Native.



        To answer your bullets:



        1. No, the same compiler is used whether or not you have Java source files.

        2. Probably not. Kotlin JVM is made to be almost completely interoperable with Java, and that's the same whether or not your project includes Java code.

        Think about if you were creating an Android library in Kotlin. Would you really want it to automatically compile to something other than Java bytecode in that case? It wouldn't be able to be used in Java projects, defeating one of the main reasons Kotlin is so good as a Java alternative.



        Also remember, you're using the Android SDK. Even if you have no dependencies in your build.gradle, you still reference the core SDK itself, which is Java. The SDK isn't included in your APK, but it's still used during compilation.



        If you want something that avoids Java bytecode, use something like Flutter. It has its own SDK, and can bridge back to Java components. Of course, you can't completely avoid the JVM, because you still need some way for Android to install and open the app.






        share|improve this answer













        The only way you're going to avoid Java bytecode with Kotlin is to use Kotlin Native, and you won't be able to use the Android SDK in that case.



        Kotlin JVM, as the name implies, compiles to JVM bytecode; it's one of the main draws of using it. If it compiled to something different, it would be Kotlin Native.



        To answer your bullets:



        1. No, the same compiler is used whether or not you have Java source files.

        2. Probably not. Kotlin JVM is made to be almost completely interoperable with Java, and that's the same whether or not your project includes Java code.

        Think about if you were creating an Android library in Kotlin. Would you really want it to automatically compile to something other than Java bytecode in that case? It wouldn't be able to be used in Java projects, defeating one of the main reasons Kotlin is so good as a Java alternative.



        Also remember, you're using the Android SDK. Even if you have no dependencies in your build.gradle, you still reference the core SDK itself, which is Java. The SDK isn't included in your APK, but it's still used during compilation.



        If you want something that avoids Java bytecode, use something like Flutter. It has its own SDK, and can bridge back to Java components. Of course, you can't completely avoid the JVM, because you still need some way for Android to install and open the app.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 16:27









        TheWandererTheWanderer

        7,05721028




        7,05721028



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284773%2fkotlin-bytecode-in-android-apps%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto