How to add Kotlin support to your flutter project? How to add Kotlin support to your flutter project? flutter flutter

How to add Kotlin support to your flutter project?


You simply have to add a single file in Kotlin format (example under android>main>java>your packagename>test.kt and it will automatically upgrade. Can be an empty file. Add it using android studio. answer reference: https://github.com/mintware-de/flutter_barcode_reader/issues/121


Doing it manually:

Check if you need to do this:

https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

Next create a new flutter project for reference and call it myapp.

Next, from myapp/android/build.gradle copy:

ext.kotlin_version = '1.3.50'

and

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

Next, from myapp/android/app/build.gradle copy:

apply plugin: 'kotlin-android'

and

sourceSets {    main.java.srcDirs += 'src/main/kotlin'}

and

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Next, create the path according to you package path and copy the file myapp/android/app/src/main/kotlin/com/example/myapp/MainActivity.kt

Next, in the file MainActivity.kt replace 'package com.example.myapp' with your package.

Next, if MainActivity.java is an empty class then just delete it under ../android/app/src/main/java/..but if it is not then you will need change the class and its body to kotlin, copy it and only then delete it.