Programming/Qt

Setting Up adb Debugging and Viewing Logcat Messages with Qt

변화의 물결1 2024. 11. 6. 17:16

 

 

안녕하세요.

 

 Qt 프로그래밍이 국내보다는 외국에서 조금 더 많이 사용하는 것으로 생각되어 영문으로 내용을 구성해 보았습니다. 쉬운 글로 되어 있으니 어렵지 않게 흐름 파악을 할 수 있을 것이라 생각됩니다.

 

 

 When developing an Android app with Qt, basic debugging can be done through the Application Output. However, as you dive deeper into development using JNI and similar features, you may find the Output messages insufficient.

 

 You’re likely already using Logcat in Android Studio.

 

 The instructions below explain how to view adb logcat messages directly in Qt, allowing you to check messages within the program (Qt) without needing to run multiple applications.

 


  

1. Checking the adb Path

 

 The following steps are based on a debugging environment using Qt 6.7.3 and Android Studio Koala Feature Drop | 2024.1.2. Before configuring adb in Qt, you need to verify the adb path.

 

 Open Android Studio and go to File > Settings > Languages & Frameworks > Android SDK to locate the path.

 

 Copy this path and paste it into the address bar in Windows Explorer.

 

 

 

 In the SDK path, you will find a folder named "platform-tools". Inside this folder, you’ll see adb.exe and other programs needed for Android app debugging. Copy or note this path, as you’ll use it in Qt below.

 

 

 

2. Configure adb in Qt

 

 Assuming that you’ve already set up Android app development with the necessary configurations, including an Android Virtual Device (AVD) for the emulator:

 

 In Qt, go to "Tools > External > Configure > Environment > External Tools".

 Select "Add Tool" and input the following details:

 

 

 

Name: adb tool

Description: This is a tool for Android app debugging. (Optional)

Executable: Paste the path to adb.exe (e.g., C:\Users\____\AppData\Local\Android\Sdk\platform-tools\adb.exe)

Arguments: logcat *:* (This will output all messages; refer to section 4 for more targeted options)

 

Click Apply or OK to save.

 

 

 

 

In the top menu under "Tool -> External," you will see the "adb tool" that you created earlier.

 

 

 When you select the "adb tool" menu, adb.exe will run in the "General Messages" window. If the AVD is not running, it will display "waiting for device." If the AVD is already running, various types of messages will appear.

 

 

 

3. Comparing Android Studio Logcat and Qt Creator’s General Messages

 

1) Android Studio Logcat:

 

 Being a dedicated Android tool, it color-codes messages by log level, making it visually organized.

 

 

 

2) Qt Creator Logcat

 

 Since this is not a dedicated Android app program, the messages appear as text-based output separated by tab spacing.

 

 

 

You can see that the log timestamps in both programs are the same, confirming that while the visual presentation differs, both programs provide the same functionality.

 

 

4. Filtering Logcat Output

 

 Here are some helpful ways to filter Logcat messages. Use the formats below in the Arguments section in Qt without the adb part:

 

1) Basic adb logcat Filter Format

 

 The adb logcat command allows you to filter logs based on tags and log levels. The basic format is as follows:

 

adb logcat [TAG]:[LEVEL]

 

TAG: Specifies a particular log tag (e.g., MyAppTag, ActivityManager, DEBUG).

LEVEL: Specifies the log level. Possible levels are:

 

V: Verbose (shows all logs)

D: Debug (debugging logs)

I: Info (informational logs)

W: Warning (warning messages)

E: Error (error messages)

F: Fatal (critical errors)

S: Silent (displays no logs)

 

2) Filter Examples

 

(1) Display all logs

 

adb logcat *:V

 

Displays all logs for all tags and log levels.

 

 

(2) Show all logs from a specific tag

 

adb logcat MyAppTag:V *:S

 

Displays all logs for the MyAppTag tag, while all other tags are set to Silent and will not display.

 

 

(3) Display a specific tag with a minimum log level

 

adb logcat MyAppTag:D *:S

 

Shows only Debug and higher logs for the MyAppTag tag, while other tags remain silent.

 

 

(4) Specify multiple tags with different log levels

 

adb logcat MyAppTag:D AnotherTag:I *:S

 

Displays logs from MyAppTag at Debug level and above, and logs from AnotherTag at Info level and above. All other tags are silent.

 

 

(5) Show only Error-level and above logs for all tags

 

adb logcat *:E

 

Displays Error level and above for all tags.

 

 

3) Common Filter Combinations

 

View only crash logs: Useful for catching Fatal Exceptions that occur when the app crashes.

 

adb logcat *:E

 

General debugging for a specific app:

 

adb logcat MyAppTag:D *:S

 

This is helpful when you only want Debug or higher logs for your app's specific tag, ignoring all other tags.

 

Using these filters helps streamline logs, making debugging easier by focusing only on relevant output.

 

 

 

<Reference>

1. Logcat Command-Line Tool

https://developer.android.com/tools/logcat?hl=en  

 

 

반응형