Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Use Kotlin in an Existing Android App?

Tags:

kotlin

I have an Android App developed using Java. I now want to start using Kotlin for the same app. Is it possible to use Kotlin and Java side-by-side in an existing app?

like image 853
Sachin Gawai Avatar asked Jul 11 '17 04:07

Sachin Gawai


2 Answers

Yes you can mix Java and Kotlin in one project.

From Android doc :

If you're interested in using Kotlin, it's easy to get started because it works side by side with Java and C++ on Android. So you can keep your existing code, continue to use the various Android libraries, and incrementally add Kotlin code to your project. Unlike almost any other language, Kotlin is a drop-in replacement you can use bi-directionally—you can call into the Java language from Kotlin, and you can call into Kotlin from the Java language.

Also you should take a view of kotlin official doc


You can also convert Java code to Kotlin with IntelliJIDEA.

like image 101
Abhishek Aryan Avatar answered Oct 08 '22 03:10

Abhishek Aryan


simplest way to do this is :

  1. right click on app folder
  2. select new
  3. kotlin file/class
  4. any directory with any name "KotlinTest"
  5. it will prompt you to configure
  6. select appropriate module or all modules(if you are using wear also in your project)
  7. this will start automatic installation
  8. delete KotlinTest class
like image 28
Swapnil Kadam Avatar answered Oct 08 '22 05:10

Swapnil Kadam