Android Tutorial Convert Java to Kotlin

Android Tutorial Convert Java to Kotlin

You may have a bunch of old or existing Android projects in your machine created using Java. If you haven’t already known about it, Google is slowly changing their support for projects created with Java to the ones created with Kotlin. In this tutorial, we will learn how to convert Java Files in Android Application to Kotlin Files or Classes.

Open existing Android Studio project

Start Android Studio 3.0 and click on “Open an existing Android Studio project”.

Open existing Android Studio project

In this already existing Android Studio project, we have two activities MainActivity.java and SecondActivity.java

Convert Java file to Kotlin file

Open MainActivity.java. Click on “Code” in Menu bar, and then on “Convert Java File to Kotlin File”. Repeat the process for all the Java Classes in your Android project that you want to be converted to Kotlin Classes.

Configure Kotlin

If you get a message “Kotlin not configured”, Click on “Configure” link provided in the message. Keep the defaults in the dialogue box “Configure Kotlin in Project” and click “OK”.

If Gradle Sync is required, proceed with the sync.

Once the Gradle sync is done, the project should be without any errors as shown below.

Run the app

Conclusion

We do hope you enjoyed this tutorial. Let’s keep the train moving!

Leave a Reply

Your email address will not be published. Required fields are marked *