6

I wrote a simple library, which I use in my main Android Studio project. I imported that *.aar library to my main project and I can instatiate objects from that library or call methods from there.

I also have log outputs like: Log.d(TAG, "Lala"); but I can not see them on logcat when I run my main app. (I jut see log outputs from my main app, but not from the *.aar library)

How can I see those log outputs on logcat?

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

1 Answers1

0

If you look to the upper right of your Logcat pane in Android Studio, you will see a dropdown pane that says 'Show only selected application'. This refers to the package and pid selected in the dropdown pane to the right of the device dropdown on the top left of the Logcat tool window. You can change the right dropdown to 'no filters' or a custom filter config with multiple process IDs.

You could also try wrapping calls made into your library in try/catch blocks, then throw exceptions instead of simply logging them from your library. If all else fails and you can't figure out how to adjust the filter Android Studio uses, that should get the message into your application name space and PID for logging... You could also start verbose logcat from terminal and it won't have any of the filter Android Studio puts on top getting in your way. Just start piping the output to a file from terminal with adb logcat -v > output.log right as you start to test whatever you need logging on.

Also, I recommended changing the filter from "Show only selected application" to "No Filters" because that is how they label the selections in Studios logcat filter menu. This does not mean show logging only from other applications. This means do not filter logging to only show logs from the namespace of the the package being installed (i.e. com.example.my), but instead show logging from any package name including that of the library in use in the project. Logcat is a broad standalone service of ADB and AS does not know to include package logs solely because said package is in the project view.

Z3r0CooL
  • 131
  • 1
  • 7
  • This does not cover the use case described in the question. – iwolf Mar 18 '21 at 23:33
  • How does it not cover the use case in the question? They said they can instantiate objects from the library, but sees no output from his log lines in the same library. I instructed them to open his logcat filtering restrictions to include logging outside of the scope of their application source code. They stated they are using Android Studio; so they're not simply reading `adb logcat -v`. When they launch the application through Android Studio it automatically sets three dropdown menus, 'target device', 'target package' and 'show only'. These limit logcat output in Android Studio; their issue. – Z3r0CooL Mar 28 '21 at 07:04
  • They're not talking about trying to see logs from other applications, they're talking about log visibility of a nested library inside their own app. In all my experimentation, even fully unfiltered logcat will not show logs from the nested aar despite provable invocations. – iwolf Mar 31 '21 at 21:22
  • Then you also must not know enough about Android Studio logcat filtering. Logcat is an individual service of ADB and all logging comes across it unless disabled in the build; if a release build excludes debug logging for example. If the library in use is printing to logcat, then it will come across logcat in android studio, granted the necessary filtering changes have been made. I have been developing an aar for my employer for over a year now, almost exclusively doing library work. I have integrated it into many of other projects for testing of which involves reading my logs in said projects. – Z3r0CooL Jul 06 '21 at 23:35
  • I see a lot of your background is in C, GCC and assembly and other things, wolf. So I wouldn't blame you for not knowing that Android Studio filters the logcat output in more ways than listed in the IDE. By the time the user is able to set filters based on Package, Device, Log level or term with RegEx support, Studio has already applied several other filters. – Z3r0CooL Jul 10 '21 at 19:07
  • "Android Studio filters the logcat output in more ways than listed in the IDE." So this is the remaining crux of the question. Do you actually have a solution for modifying these other, hidden Android Studio filters you keep alluding to, or do you always have to side-channel it through a separate command line to see the embedded aar logs? – iwolf Jul 23 '21 at 22:08
  • If you want to use a side-channel simply open terminal or command prompt and run `add devices` so it kills the bridge instance studio is using and restarts it in your prompt window. Then run it again to make sure the device being tested is picked up. Then run `adb logcat -v > output.log`. The output will hang while piping the output, run the portion of your app you expect logging in. cmd/ctr-c on the prompt to stop logging. Open the file you piped the output to; in this case `output.log`, and search for a string contained in the tags of your AAR logs. – Z3r0CooL Jul 28 '21 at 02:06
  • You may also have to ensure you are using a debug log of your library in the project. If you still have issues, you can always have the library write its logs to a file on the device and pull that file off to examine afterwards.. I think that solution should be easy enough for anyone to implement. – Z3r0CooL Jul 28 '21 at 02:06
  • Also, here is someone with a simple solution to getting logs from third party AARs: https://stackoverflow.com/questions/57919748/include-aar-library-module-logs-into-android-application-file-logger So you should have no issues logging from your own AAR. This answer should be sufficient enough even for non-AndroidStudio pros to follow.... don't forget the manifest entry. Now back to building my custom M1 Studio implementation. – Z3r0CooL Jul 28 '21 at 02:07