Upon reading the README
file of barcode_scan plugin I encountered the instruction
This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See installing the Kotlin plugin.
The link only provides information about creating Kotlin project in Android Studio. How does one add Kotlin
support for a flutter project? Is it even necessary?
EDIT: Since I already have an existing flutter package, I am looking for ways to add Kotlin
support to that project
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.
Google formally launched Kotlin support for Android mobile app development in 2019. But it's also critical to remember that Google developed the open-source mobile application development framework known as Flutter. Kotlin and Flutter both have a Google Label associated with them.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With