How to deal with flutter Java/Kotlin

486

Since the latest version of flutter the android project is created with kotlin by default. You can change this deleting the android folder and recreating it running the command below in the root of your project.

flutter create -a java .

Share:
486
LearnToday
Author by

LearnToday

Updated on December 21, 2022

Comments

  • LearnToday
    LearnToday over 1 year

    I just noticed my flutter app, the android version is in Kotlin, that is the kotlin directory contains the MainActivity.kt

    If I did this, it was a mistake because I don't know any Kotlin.

    I would prefer my android app in Java, which is the MainActivity.java under the java folder.

    How do I go about changing things so my android app is in Java?

    • John Joe
      John Joe almost 4 years
      why you need to change your kotlin code? Just change in flutter.
    • LearnToday
      LearnToday almost 4 years
      I wanted to use a plugin that is in Java, the scripts for the plugin are in java. For instance I have a file call application.java that I am suppose to place on the same path as MainActivity.java. But I don't have MainActivity.java. What I have is MainActivity.kt. That won't work, will it?
    • Tenfour04
      Tenfour04 almost 4 years
      Im guessing it will work anyway. Java and Kotlin are interoperable. At runtime there will be no difference between.java and .kt files, besides some irrelevant (to you) meta data, because they both get compiled to bytecode.