Closed Bug 1393503 Opened 2 years ago Closed 2 years ago

Gradle build failure in Android Studio: The current character read is 'C' with an int value of 67, in settings.gradle

Categories

(Firefox Build System :: Android Studio and Gradle Integration, defect, P1)

defect

Tracking

(firefox57 fixed)

RESOLVED FIXED
Tracking Status
firefox57 --- fixed

People

(Reporter: mcomella, Assigned: gps)

References

Details

(Whiteboard: [mobileAS])

Attachments

(4 files)

I mach build, package, install, and run ./mach gradle assembleLocalPhotonDebug, all successfully. However, Android Studio gradle builds fail with the following error:

Error:
FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/mcomella/dev/moz/settings.gradle' line: 18

* What went wrong:
A problem occurred evaluating settings 'moz'.
> Unable to determine the current character, it is not a string, number, array, or object
  
  The current character read is 'C' with an int value of 67
  Unable to determine the current character, it is not a string, number, array, or object
  line number 1
  index number 0
  Could not find 'hg' on the path.
  ^

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

---

Looking at the code [1], it looks like we're failing because we read "Could not find 'hg' on the path.", rather than valid JSON, from the command: "${topsrcdir}/mach", "environment", "--format", "json", "--verbose". Running the command locally, I do not see the hg-is-missing! text. Note that my hg is installed through homebrew: /usr/local/bin/hg

Chenxia saw this yesterday after pulling down m-c and I just got it today (with a fresh m-c pull). Chenxia also had some success by closing and restarting AS (or something like that).

Note: this should be high priority: we have a 57 deadline (for AS) coming up and while we can still build (via gradle command line or mach), this makes it non-trivial to use the debugger which could affect our ability to reach the deadline.

[1]: http://searchfox.org/mozilla-central/rev/48ea452803907f2575d81021e8678634e8067fc2/settings.gradle#18
Chris, do you know what might have changed in the build system to cause this?
Flags: needinfo?(cmanchester)
Note: this fails in "gradle project sync" (a prerequisite for building) rather than an explicit build.
I printed the contents of `standardOutput.toString()` to the console with --debug and I get:

09:31:22.485 [QUIET] [system.out] Could not find 'hg' on the path.
09:31:22.486 [QUIET] [system.out] {"defines": {"A11Y_LOG": "1", "ACCESSIBILITY": "1", ...

So it first dumps this hg warning line, then it dumps the defines, which I presume it was trying to read in the first place.
Attached patch Workaround patchSplinter Review
Found a workaround where we just skip over the bad line - I'm not sure there are any side effects from this change.

Unfortunately, I should focus on direct AS work so I will not continue working on this.

fwiw, here's the command that's causing trouble: http://searchfox.org/mozilla-central/rev/48ea452803907f2575d81021e8678634e8067fc2/python/mozbuild/mozbuild/mach_commands.py#1541
Comment on attachment 8900806 [details] [diff] [review]
Workaround patch

Review of attachment 8900806 [details] [diff] [review]:
-----------------------------------------------------------------

Land this ASAP to unblock devs, and then we'll fix the real issue ASAP.

::: settings.gradle
@@ +12,5 @@
>  if (proc.exitValue() != 0) {
>      throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${proc.exitValue()}:\n\n${standardOutput.toString()}")
>  }
>  
> +def workaround = standardOutput.toString().split('\n')[1]

Include a link to this ticket.
Attachment #8900806 - Flags: review+
mcomella: your analysis looks good.  I expect the message is being printed somewhere by a caller of http://searchfox.org/mozilla-central/source/third_party/python/which/which.py#249; we could breakpoint in pdb there to discover who the offending caller is, and muffle that print when we're producing JSON.

Hopefully chmanchester or gps can fix it.
Thanks for the workaround! Android Studio builds now, but fwiw, I see other errors when doing gradle assemble:

> mach gradle assembleLocalPhotonDebug

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/liuche/code/moz/mozilla-central/settings.gradle' line: 16

* What went wrong:
A problem occurred evaluating settings 'mozilla-central'.
> 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.549 secs

Flagging gps in the needinfo too, he might know what caused this fallout.
Flags: needinfo?(gps)
The only thing I've seen go by recently is bug 1392886. It looks like one of those patches could cause us to attempt to detect hg more often via mozversioncontrol, which has a function `get_tool_path` that will print a WhichError consistent with this output.
Flags: needinfo?(cmanchester)
(In reply to Chenxia Liu [:liuche] from comment #7)
> Thanks for the workaround! Android Studio builds now, but fwiw, I see other
> errors when doing gradle assemble:

So new workaround steps, if you clobber or need to run via `mach gradle`:
- clobber
- build & assembleLocalPhotonDebug (no workaround applied)
- Apply workaround
- gradle sync Android Studio and continue building with Android Studio
What is the exact command that is failing (presumably some invocation of `mach environment`) and what is its exact output?
Component: Build Config & IDE Support → Build Config
Flags: needinfo?(gps) → needinfo?(michael.l.comella)
Product: Firefox for Android → Core
(In reply to Gregory Szorc [:gps] from comment #10)
> What is the exact command that is failing (presumably some invocation of
> `mach environment`) and what is its exact output?

We execute a process with the following from gradle (via [1]) within Android Studio (note that the user environment/paths will be different here):
  ["${topsrcdir}/mach", "environment", "--format", "json", "--verbose"]

And Android Studio dumps the following in the console:

Gradle sync failed: Unable to determine the current character, it is not a string, number, array, or object
			The current character read is 'C' with an int value of 67
			Unable to determine the current character, it is not a string, number, array, or object
			line number 1
			index number 0
			Could not find 'hg' on the path.
			^
			Consult IDE log for more details (Help | Show Log)

---

And also dumps idea.log in Library/..., whose contents is in the attachment.

Note that I was able to get gradle to run with additional output (--info & --debug) at one point but I can't seem to replicate that (yay, IDEs!).

[1]: http://searchfox.org/mozilla-central/rev/48ea452803907f2575d81021e8678634e8067fc2/settings.gradle#5
Flags: needinfo?(michael.l.comella) → needinfo?(gps)
And what's the output from `mach environment --format json --verbose` when you run that in a shell?
Flags: needinfo?(gps) → needinfo?(michael.l.comella)
I /think/ I can reproduce this.
Assignee: nobody → gps
Status: NEW → ASSIGNED
Depends on: 1392886
Flags: needinfo?(michael.l.comella)
Heh - your shell doesn't emit the message causing the failure. I guess something somewhere is setting PATH to either nothing or something without `hg` in it. Wonky.

My patch should fix things though by getting rid of the printing of the "not found" message.
Comment on attachment 8900967 [details]
Bug 1393503 - Proper error handling for failure to find VCS tool;

https://reviewboard.mozilla.org/r/172420/#review177718

lgtm.
Attachment #8900967 - Flags: review+
Comment on attachment 8900967 [details]
Bug 1393503 - Proper error handling for failure to find VCS tool;

https://reviewboard.mozilla.org/r/172420/#review177722
Attachment #8900967 - Flags: review?(mh+mozilla) → review+
Pushed by gszorc@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8c56313471f8
Proper error handling for failure to find VCS tool; r=glandium,nalexander
https://hg.mozilla.org/mozilla-central/rev/8c56313471f8
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Component: Build Config → Build Config & IDE Support
Product: Core → Firefox for Android
Target Milestone: mozilla57 → ---
Product: Firefox for Android → Firefox Build System
You need to log in before you can comment on or make changes to this bug.