Search code examples
androidkotlinlive-templates

Live Template not working in Kotlin


Hope you have worked with Live Templates which is given by Android by default.

Like:

Generate debug log statement: "logd"+TAB
Generate error log statement: "loge"+TAB
Generate info log statement: "logi"+TAB
Generate TAG declaration: "logt"+TAB
Generate parameter logging: "logm"+TAB
Generate method return log: "logr"+TAB

enter image description here

Which it is not available in KOTLIN?

Is it not available in Android Studio 3.0 Canary Version?


Solution

  • Yet not added log template in Kotlin Live templates section in Android Studio.

    Settings -> Editor -> Live Templates -> Kotlin for kotlin templates.

    kotlin templates

    Settings -> Editor -> Live Templates -> AndroidLog for AndroidLog templates

    AndroidLog  templates.

    So you can't get the same AndroidLog templates in Kotlin code.

    So now Question is How to use same Log Functions using templates in Kotlin?

    Ans: You can add same Log templates (AndroidLog Templates) in Kotlin Templates section in Android studio as below example.

    Kotlin Templates section

    Then It will be available in your Kotlin code!

    Kotlin loge

    I hope in this way you can get an advantage of Log functions templates in Kotlin.