Reputation: 1860
I am trying to write to adb logcat from my flutter app.
The code I have is as follows. It is just the default init project, with some print writes.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
print("HELLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
_counter++;
});
}
@override
Widget build(BuildContext context) {
print("HELLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Once I install to my USB debugging device, I run...
adb logcat
From the terminal. There is lots of logging happening when I do this, but nothing shows up from my flutter application.
When I instead run flutter run , then the print statements will show up in the terminal from which I ran it.
Why is nothing showing up in adb logcat?
Upvotes: 18
Views: 13825
Reputation: 164
Use
log('Message******************* $info');
You need to import import 'dart:developer';
Upvotes: 4
Reputation: 4443
[Edit: This answer is outdated, check Luciano Ribas's answer for newest solution]
Flutter use Run tab to display logs in Android Studio (or DEBUG CONSOLE in VSCode). That's mean adb logcat
could not show any thing because it not supported by Flutter. More detail here and here.
However, you could use flutter logs
instead of adb logcat
to get your log when you run an apk which installed on your device (debug mode). Sadly, sometime it not work (tested: ~30%).
$ flutter logs
Showing <device name> logs:
$ flutter logs
Showing <device name> logs:
I/flutter (<pid>): Observatory listening on http://127.0.0.1:34710/<secret key>/
I/flutter (<pid>): <your log>
...
flutter pub global run devtools
after that.$ flutter pub global run devtools
Serving DevTools at http://127.0.0.1:9100
http://127.0.0.1:34710/<secret key>/
link got from command line for start DevTools.Upvotes: 18
Reputation: 389
Actually in flutter 3.0.2 that works as expected and have the same result as flutter log
, just execute:
adb logcat | grep flutter
Upvotes: 5