Issue
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?
Solution
[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%).
- Step 1: Run the commend below.
$ flutter logs
Showing <device name> logs:
- Step 2: Start your application.
$ 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>
...
- Step 3: Read log from command line or start a new command prompt and run
flutter pub global run devtools
after that.
$ flutter pub global run devtools
Serving DevTools at http://127.0.0.1:9100
- Step 4: Use the
http://127.0.0.1:34710/<secret key>/
link got from command line for start DevTools.
Answered By - Trần Đức Tâm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.