Kotlin print() method dosen't work in Flutter

Question

Asked by zaynOm on November 24, 2021 (source).

I'm trying to debug android native code (kotlin) for flutter using the print().

The problem I'm facing is that it doesn't print in the console when I run the app.

class MainActivity : FlutterActivity() {
    private val channel = "com.example.pomo_app/mychannel"

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel)  
          .setMethodCallHandler { call, result ->
                    when (call.method) {
                        "getAllRingtones" -> {
                            // this doesn't print to console
                            print("Native code works")
                          
                        }

Answer

Question answered by Eugene K (source).

You have to use Log.d("TAG", "your log message") for Android native logs.

Kotlin print() and println() methods won't work.

Bit if you want to log some native ios code, you can use print() and println() methods in Swift

ANDROID DART FLUTTER KOTLIN
SHARE: