简体   繁体   中英

Android Studio not showing Logcat with Flutter

I'm using Android Studio for Flutter App Development. Everything seems to be working fine just that the Android Studio does not show the "logs" in Logcat. In the Logcat section, it says "Please Configure Android SDK". Which is already configured. And in the Logcat section says "No Connected Devices." in the drop-down menu. When it has recognized my Android Phone and is showing it just under the Menu bar.

Is there a fix for it? Is there something I am missing?

在此处输入图像描述

Try the following:

  • Event Log ( a tab at the bottom right ) 在此处输入图片说明

  • scroll to Android framework is detected

在此处输入图片说明

The Logcat tab should appear now. Moreover, Device File Exprorer should show up on the right panel.

Update April 2020: Cuong's answer works better with Android Studio 3.6+


Previous answer:

Flutter use Run tab to display logs in Android Studio. Switch from Logcat to Run and then you will see logs.

转到设置/首选项 -> 语言和框架 -> Flutter -> 选中或取消选中Replace the Run and Debug console with an Experimental Flutter Loggin view

When I first came to Flutter from an Android background, I didn't know where to find the log statements. I didn't care so much about all of the system messages. I just wanted to see log messages from my app during development. This answer is for people like that, not for people who specifically need LogCat itself.

In Flutter apps you can log text using the print() statement.

print('hello');

As others have said, you can use the Run tab in Android Studio to view these logged comments.

在此处输入图片说明

Here is the code for main.dart:

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Center(
      child: RaisedButton(
        child: Text('Button'),
        onPressed: () {
          print('hello'); //               <-- logging
        },
      ),
    ),
  ));
}

Just open another NATIVE project for Android Studio in other window and the logcat will work, do it while Flutter project is open. That was the solution for me

I just solved this, the flutter project was missing an Android module. Go to 'File -> Project Structure -> Modules'. Click on the '+' sign at the top to add a module. Select Android.

I had this issue: I have done the following steps to resolved it:

  • Click the event log on the bottom right of android studio在此处输入图片说明
  • Click on configure在此处输入图片说明
  • Click on Ok in the dialog box

在此处输入图片说明

  • Logcat will be available now 在此处输入图片说明

Open Project Stucture -> Modules -> new android module from exists source.

Logcat & Device File Explorer will be visible.

for Android Studio 3.6: File -> New -> New Module -> Android Library

I guess it's an ADB issue. You can restart AS (or maybe even your Computer) or what i usually do is open the terminal an then: adb kill-server && adb start-server (I think the second part adb start-server is not necessary because it seems that AS handles it automatically) - anyways this is how LogCat and Android (and Flutter) work for me every time.

When i face this problem I just go to File and open my existing native android project and then close it. This solution also works when abd Wifi pludings does show warning like => adb not found.

只需使用命令 'flutter logs',然后您就可以看到由 'print' 或 'debugPrint' 函数打印的所有日志。

when you open flutter project, IDE prompts you to configure android project. Just click on the recommendation and it will start showing logcat window.

In case you accidentally refused to configure Android framework and now struggling to find the LogCat window. Then delete .idea, .dart_tool and .gradle folders in project root and android folder. Then Invalidate and restart. It will ask to configure detected Android framework. Click 'configure'.

Simple way

1.

Go to Menu and select 'Project Structure' -> 'Project'

在此处输入图片说明

2.

In 'Project Structure' Select Project SDK

在此处输入图片说明

And just now click on OK and Apply.

thank you.

Find a way around it (macOS).

Go to Project Structure -> Facets -> "+" -> Android -> Select Project Logcat should now be visible. Configure Android SDK if not done previously and you should be able to use Logcat.

Reference https://github.com/flutter/flutter-intellij/issues/2724

切换到“运行”选项卡以查看日志,如果您想插入日志(如 android 中的Log.d() ),您可以使用print()函数,您传递给它的任何字符串都将打印到“运行”窗口。

I found a solution worked for me:

for MacOS: Go to: /Users/userName/Library/Preferences/AndroidStudio3.4/options Find "runner.layout.xml" Change the name of this file for ex: runner01.layout.xml Restart Android studio

for Windows: 1- Focus "Run" tab (click on tab header, not on its body) 2- Ctrl+Shift+A, find and click "Restore Layout"

References: https://github.com/flutter/flutter/issues/25835 https://github.com/flutter/flutter-intellij/issues/3673#issuecomment-517356243

Hopefully, it helps.

You can enable verbose logging for flutter if you are looking for AppId or something of that sort.

在此处输入图片说明

In my case, I also had an error in the Device File Explorer: Error initializing ADB: Android Debug Bridge no found . I fixed the problem following Error initializing ADB: Debug Bridge not found : I selected the latest Android API Platform as Project SDK in File/Project Structure.

只需转到File => Project Structure => 并在“ SDK project ”中选择“ Android

  1. close project
  2. delete .dart_tool,.idea,build files
  3. start android studio,logcat will display

Run

adb logcat

and watch from terminal. Doc: https://developer.android.com/studio/command-line/logcat

In new versions of Android Studio, after deploying the app to device/emulator, in Run Tab you will see an option for flutter dev tools as shown in the image, it will open in browser (based on default chrome/edge) and there you can see logcat/logging

运行选项卡的 Android Studion artic

Flutter Dev Tools

Google Chrome 中的 Flutter 开发工具

  1. Go to File > Project Structure<\/code> Project or use cmd<\/kbd> + ;<\/kbd> or

    <\/li>

Some times for some reasons like flutter clean or changing in files directory, android studio usually excludes some files from project modules. here is some simple steps to help you solve the problem:

go to File --> Project Structure --> Modules

There are 2 common scenarios.

  • Android studio might have completely removed your project from modules. For this you need to add it again using steps shown in the picture below.

Click on the plus icon and the add your project here. Then press Apply and lastly OK.

在此处输入图像描述

  • Android studio just excluded some of the files and folders from your flutter project. In the right panel you can see them in red. just remove them from exclude list and again Apply and OK.

在此处输入图像描述

NOTE: In both scenarios you need to stop the project and rerun it. or better close and reopen android studio

Flutter没有 logcat flutter 在运行选项卡内的控制台中显示错误。如果您想查看错误和崩溃报告,请单击运行选项卡。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM