java.interop
java.interop copied to clipboard
XML syntax warnings when using JavaSourceJar
Error Message or Issue
After upgrading to VS 16.10 (from 16.4), I get several general XML syntax errors when trying to compile the https://github.com/Baseflow/ExoPlayerXamarin binding library:
Severity Code Description Project File Line Suppression State Error (1 24): Syntax error, expected: #PCDATA, <tt>, <TT>, <i>, <I>, {@code, {@docRoot}, {@inheritDoc}, {@link, {@linkplain, {@literal, {@value}, {@value, UnknownHtmlElementStart, <p>, <P>, <pre>, <PRE>, @author, @apiSince, @deprecated, @deprecatedSince, @exception, @param, @return, @see, @serialData, @serialField, @since, @throws, @[unknown], @version ExoPlayer.Common C:\Craigs Files\Apps\ExoPlayerXamarin-develop\ExoPlayer.Common\BINDINGSGENERATOR 1
Version Information
Other Helpful Info
I think the only current workaround for this is to remove the <JavaSourceJar> files from your .csproj files.
<JavaSourceJar Include="JavaDocs\*.jar" />
@cncb-gh: How are you observing this error? It looks like you have $(TreatWarningsAsErrors) disabled:
https://github.com/Baseflow/ExoPlayerXamarin/blob/5214b7158fc6611f602ffc0f0122429a3ae49b6d/Directory.Build.props#L22
We should only be emitting a warning for this, and probably not even a warning… (We should fix that.)
I don' t know - they are showing up as errors in the Build Output as well as the Error List. Is there another setting in VS that might affect this?
I tried removing the source jar files and now get invalid token errors in some generated files. It is placing '?' in some methods like so (notice "void?"):
[Register ("writeToParcel", "(Landroid/os/Parcel;I)V", "GetWriteToParcel_Landroid_os_Parcel_IHandler")] public abstract void? WriteToParcel (global::Android.OS.Parcel? dest, [global::Android.Runtime.GeneratedEnum] global::Android.OS.ParcelableWriteFlags flags);
Looks like this is the full output message that is being emitted:
## Unable to translate remarks for com/google/android/exoplayer2/Player:
A media player interface defining traditional high-level functionality, such as the ability to
play, pause, seek and query properties of the currently playing media.
<p>
Some important properties of media players that implement this interface are:
<ul>
<li>They can provide a {@link Timeline} representing the structure of the media being played,
which can be obtained by calling {@link #getCurrentTimeline()}.</li>
<li>They can provide a {@link TrackGroupArray} defining the currently available tracks,
which can be obtained by calling {@link #getCurrentTrackGroups()}.</li>
<li>They contain a number of renderers, each of which is able to render tracks of a single
type (e.g. audio, video or text). The number of renderers and their respective track types
can be obtained by calling {@link #getRendererCount()} and {@link #getRendererType(int)}.
</li>
<li>They can provide a {@link TrackSelectionArray} defining which of the currently available
tracks are selected to be rendered by each renderer. This can be obtained by calling
{@link #getCurrentTrackSelections()}}.</li>
</ul>
Error (31:41): Syntax error, expected: #PCDATA, <tt>, <TT>, <i>, <I>, {@code, {@docRoot}, {@inheritDoc}, {@link, {@linkplain, {@literal, {@value}, {@value, UnknownHtmlElementStart, </tt>, </TT>, </i>, </I>, </p>, </P>, <p>, <P>, <pre>, <PRE>, @author, @apiSince, @deprecated, @deprecatedSince, @exception, @param, @return, @see, @serialData, @serialField, @since, @throws, @[unknown], @version
{@link #getCurrentTrackSelections()}}.</li>
^
This part:
Error (31:41): Syntax error, expected: ......
Is close enough to the MSBuild error format that MSBuild seems to be recognizing it as an actual error, which is not intended.

I think if we change this line to something else we can get this back to an informational message as intended:
// JavadocInfo.cs: 189
writer.WriteLine ($"{m.Level} {m.Location}: {m.Message}");
I have a PR that fixes MSBuild interpreting these error messages as real errors: https://github.com/xamarin/java.interop/pull/851
I believe @pjcollins will be looking at improving the Javadoc parsing in the future to prevent the messages from happening in the first place.
(See also https://github.com/xamarin/java.interop/issues/843)
Thanks. In the meantime, do you know how I can fix the "invalid token" error when removing the JavaDoc references?
Did you remove them from all of your projects? I had tried removing them from all the projects, and did not get the invalid token errors you mentioned.
Did you remove them from all of your projects? I had tried removing them from all the projects, and did not get the invalid token errors you mentioned.
I removed them from all projects but it still adds a "void?" to WriteToParcel() for me.
I can't figure out how to avoid the void? generation. The following in metadata.xml do not work. Thanks for any help.
<remove-node path="/api/package[@name='com.google.android.exoplayer2.metadata']/interface[@name='Metadata.Entry']/method[@name='writeToParcel' and count(parameter)=2 and parameter[1][@type='android.os.Parcel'] and parameter[2][@type='int']]"></remove-node>
<attr name="return" path="/api/package[@name='com.google.android.exoplayer2.metadata']/interface[@name='Metadata.EntryInvoker']/method[@name='writeToParcel' and count(parameter)=2 and parameter[1][@type='android.os.Parcel'] and parameter[2][@type='int']]">void</attr>
You could try something like:
<attr name="return-not-null" path="/api/package[@name='com.google.android.exoplayer2.metadata']/interface[@name='Metadata.EntryInvoker']/method[@name='writeToParcel' and count(parameter)=2 and parameter[1][@type='android.os.Parcel'] and parameter[2][@type='int']]">true</attr>
Unfortunately, this didn't work for me either. The only thing that works is removing the whole Metadata class with remove-node. Thanks for your help.
Somehow even though it builds successfully, several interfaces and classes are missing in the output. I think I tracked it down to the "Player" interface never being generated. I get this warning but it does not tell me anything specific:
1>obj\Release\monoandroid10.0\api.xml(3, 6) : warning BG8C01: For type 'Com.Google.Android.Exoplayer2.BasePlayer', base interface 'com.google.android.exoplayer2.Player' is invalid.
Player Interface: https://github.com/google/ExoPlayer/blob/release-v2/library/common/src/main/java/com/google/android/exoplayer2/Player.java
BasePlayer: https://github.com/google/ExoPlayer/blob/release-v2/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java
I would appreciate any more help you are able to give. Thanks for your time.
That's not one I see very often. It means it found the interface com.google.android.exoplayer2.Player, but there is some issue with it that will prevent it from getting generated.
Hopefully there is another message somewhere in the diagnostic output that tells what is wrong with the com.google.android.exoplayer2.Player interface.
I turned on "Diagnostic" build output and unfortunately don't see anything that tells what is wrong with the interface. Just the one warning for BasePlayer about the invalid interface and several invalid parameter and return type warnings where the Player interface is attempted to be used. Here is the build output: Output-Build.txt
It's in your log:
1> C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(53,5): message BG0000: obj\Release\monoandroid10.0\api.xml(2220, 10): warning BG8801: Invalid parameter type 'com.google.android.exoplayer2.Player.Listener' for member 'Com.Google.Android.Exoplayer2.IPlayer.RemoveListener (Com.Google.Android.Exoplayer2.IPlayerListener)'.
1> obj\Release\monoandroid10.0\api.xml(2030, 6) : warning BG8503: Invalidating 'Com.Google.Android.Exoplayer2.IPlayer' and all its nested types because some of its methods were invalid.
You will need to follow the trail to figure out the root issue causing the types to be invalidated.
That is:
IPlayeris invalidated becauseIPlayerListeneris invalid- Search for why
IPlayerListeneris invalid - Repeat as needed
I traced it back to me removing the Metadata class to avoid the 'void?' token error. I have tried both your suggestion as well as
<attr name="return-not-null" path="/api/package[@name='com.google.android.exoplayer2.metadata']/interface[@name='Metadata.Entry']/method[@name='writeToParcel' and count(parameter)=2 and parameter[1][@type='android.os.Parcel'] and parameter[2][@type='int']]">true</attr>
but it always generates a 'void?' (it seems that IEntryInvoker is automatically generated by the binder for IEntry because it is not defined in Java). Any other ideas on how to solve this?
The easiest way to solve it would be to turn off <Nullable> for that assembly.
<Nullable> worked but that uncovered a number of other errors including several runtime Java.Lang.AbstractMethodError exceptions. These seem to mostly have come from a deprecated interface? I'm sure there is a better way to do it, but I had to slowly remove these methods one-at-a-time until the errors stopped. But, I finally have something running successfully so thank you!