我正在尝试从我的flutter应用程序写入adb logcat。
我的代码如下。这只是默认的init项目,带有一些打印内容。
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),
),
);
}
}
安装到USB调试设备后,我将运行...
adb logcat
从终端。当我这样做时,会发生很多日志记录,但是从我的flutter应用程序中什么都看不到。
当我改为运行 flutter run 时,打印语句将显示在运行它的终端中。
为什么adb logcat中什么都没有显示?
答案 0 :(得分:1)
Flutter (使用运行)标签显示 Android Studio 中的日志(或 VSCode中的 DEBUG CONSOLE ) )。这意味着adb logcat
无法显示任何内容,因为 Flutter 不支持。 here和here更详细。
但是,当您运行安装在设备上的apk(调试模式)时,可以使用flutter logs
代替adb logcat
来获取日志。可悲的是,有时它不起作用(经测试:约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
。$ flutter pub global run devtools
Serving DevTools at http://127.0.0.1:9100
http://127.0.0.1:34710/<secret key>/
链接启动DevTools。