Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

[AndroidToolTask] Log tool output as error - #229

Merged
pjcollins merged 6 commits into
mainfrom
dev/pjc/toolout
Apr 19, 2024
Merged

[AndroidToolTask] Log tool output as error#229
pjcollins merged 6 commits into
mainfrom
dev/pjc/toolout

Conversation

@pjcollins

Copy link
Copy Markdown
Member

Context: #208

Updates AndroidToolTask to capture all standard output from the tool and log it as an error if the task fails.

Context: #208
Updates AndroidToolTask to capture all standard output from the tool and
log it as an error if the task fails.
@pjcollins
pjcollins marked this pull request as ready for review April 8, 2024 19:57
@pjcollins

Copy link
Copy Markdown
MemberAuthor

Testing this further with dotnet/android#8861

return RunTask ();
bool taskResult = RunTask ();
if (!taskResult && !string.IsNullOrEmpty (toolOutput?.ToString ())) {
Log.LogError (toolOutput.ToString ().Trim ());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this one should have an error code, can we use $"XA{TaskPrefix}0000", maybe we can add new helper method in this class?

https://github.com/xamarin/xamarin-android-tools/blob/37d79c9dcdf738a181084b0b5890877128d75f1e/src/Microsoft.Android.Build.BaseTasks/UnhandledExceptionLogger.cs#L24

@pjcollinspjcollinsApr 8, 2024

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've attempted to address this with the latest changes that use LogCodedError instead

@jonathanpeppersjonathanpeppersApr 8, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading what @jonpryor wrote on #208:

Update AndroidToolTask so that it provides output logging infrastructure, a'la dotnet/android@b002dc38, such that all tool output is always captured (as well as logged via LogDebugMessage()), and when an error occurs, all captured output is part of the error message.

Do we somehow need to "smush" the extra error information into an existing error message? 🤦 This PR would show two errors, right?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current approach should indeed show two errors, though I think both are useful. Here is a sample of complete build output from the test case that was added:

 "OutputTest.proj" (Test target) (1:2) ->
(Test target) -> OutputTest.proj(10,9): error MSB6006: "dotnet" exited with code 1.
OutputTest.proj(10,9): error XADTOT0000: Could not execute because the specified command or file was not found.
OutputTest.proj(10,9): error XADTOT0000: Possible reasons for this include:
OutputTest.proj(10,9): error XADTOT0000: * You misspelled a built-in dotnet command.
OutputTest.proj(10,9): error XADTOT0000: * You intended to execute a .NET program, but dotnet-invalidcommand does not exist.
OutputTest.proj(10,9): error XADTOT0000: * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
0 Warning(s)
2 Error(s)

The first error shows the tool name and exit code, and the second error is our new custom error with all of the output from the tool. Do we want to try to suppress/replace the MSB6006 error?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you have here is 100% better, let's just have @jonpryor weigh in. He should be back very soon.

Comment threadsrc/Microsoft.Android.Build.BaseTasks/AndroidToolTask.cs Outdated
@pjcollins

Copy link
Copy Markdown
MemberAuthor

I think this is ready, let me know if there is anything else to consider before merging

@pjcollins
pjcollins merged commit 1ea4e35 into mainApr 19, 2024
@pjcollins
pjcollins deleted the dev/pjc/toolout branch April 19, 2024 18:37
@jonpryor

Copy link
Copy Markdown
Contributor

Doh, I was too late for an updated commit message:

`AndroidToolTask.Execute()` logs full tool output on error
Context: https://github.com/xamarin/xamarin-android-tools/issues/208
Context: https://github.com/xamarin/xamarin-android/commit/b002dc38196a0bedb18c82d228056e1ba108459c
Very often the *context* to understand a tool error isn't printed to
stderr, but is instead printed earlier to stdout. For example,
consider this annotated `r8` output snippet from
xamarin/xamarin-android@b002dc38 (`[stderr]` and `[stdout]` are
annotations):
% $HOME/android-toolchain/jdk-11/bin/java -Xmx1G -classpath …/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-preview.4.20/tools/r8.jar com.android.tools.r8.D8 --debug --min-api 23 --output obj/Debug/net7.0-android/android/bin/ …[stdout] Error in obj/Debug/net7.0-android/lp/59/jl/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class:[stdout] Type android.support.v4.app.INotificationSideChannel$Stub is defined multiple times: obj/Debug/net7.0-android/lp/59/jl/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class, obj/Debug/net7.0-android/lp/4/jl/bin/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class[stdout] Compilation failed[stdout] Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj/Debug/net7.0-android/lp/59/jl/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class[stdout] at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:98)[stdout] at com.android.tools.r8.D8.main(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:4)[stdout] Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj/Debug/net7.0-android/lp/59/jl/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class[stdout] at Version.fakeStackEntry(Version_3.3.28.java:0)[stdout] at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:75)[stdout] …[stdout] Caused by: com.android.tools.r8.internal.f: Type android.support.v4.app.INotificationSideChannel$Stub is defined multiple times: obj/Debug/net7.0-android/lp/59/jl/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class, obj/Debug/net7.0-android/lp/4/jl/bin/classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class[stdout] at com.android.tools.r8.internal.DT.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:14)[stdout] …[stderr] java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj/Debug/net7.0-android/lp/59/jl/classes.jar : android/support/v4/app/INotificationSideChannel$Stub.class
When originally processed, the *only* output included in the error
message was the the only line written to stderr:
error : java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException:Compilation failed to complete, origin: obj/Debug/net7.0-android/lp/59/jl/classes.jar :android/support/v4/app/INotificationSideChannel$Stub.class
The fix in xamarin/xamarin-android@b002dc38 was to update
`<JavaToolTask/>` to capture *all* output from `java …`, and when an
error occurred, dump *all* of it:
Update `AndroidToolTask` to do the same thing, "lowering" the logic
into a common base class of `<JavaToolTask/>`: capture all output
(stdout & stderr) from the tool, and when an error occurs, log *all*
of the captured output into an `XAccc0000` error message.
`ccc` is the `AndroidToolTask.TaskPrefix` property.

@pjcollins

Copy link
Copy Markdown
MemberAuthor

Oh sorry I jumped the gun on this, we can maybe include this in the commit message on the xamarin-android side

jonpryor pushed a commit to dotnet/java-interop that referenced this pull request May 3, 2024
Changes: dotnet/android-tools@c8a5b5b...1ea4e35
* dotnet/android-tools@1ea4e35: [AndroidToolTask] Log tool output as error (dotnet/android-tools#229)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
pullBot pushed a commit to MaxMood96/xamarin-android that referenced this pull request Jul 1, 2026
Changes: dotnet/android-tools@c8a5b5b...1ea4e35
* dotnet/android-tools@1ea4e35: [AndroidToolTask] Log tool output as error (dotnet/android-tools#229)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pjcollins@jonpryor@dellis1972@jonathanpeppers