Issue
I am trying to build a Binding Library (.AAR binding) and keep getting error as listed below:
1>BINDINGSGENERATOR : error (37: 14): Syntax error, expected: #PCDATA, , , , , {@code, {@docRoot}, {@inheritDoc}, {@link, {@linkplain, {@literal, {@value}, {@value, UnknownHtmlElementStart, @author, @apiSince, @deprecated, @deprecatedSince, @exception, @param, @return, @see, @serialData, @serialField, @since, @throws, @[unknown], @version
To replicate the issue follow the steps Binding an .AAR.
The .AAR
file, doc and sources are coming from Gecko Nightly Build geckoview-nightly-90.0.20210420095122.aar
, geckoview-nightly-90.0.20210420095122-javadoc.jar
and geckoview-nightly-90.0.20210420095122-sources.jar
Target Framework: Android 10.0(Q)
(I've tried against 9.0 as well, no luck)
*Here's a screenshot of the error's I am getting, nothing other than the BINDINGSGENERATOR
errors.
Has anyone else came across such issues when building a Bindings Library from a .AAR
file?
EDIT PER COMMENT
Version Information
- VS Version: 16.10.4
- Xamarin.Android.SDK Version: 11.3.0.4
- Xamarin Version: 16.10.000.234
Steps To Reproduce
- Create a new project (Android Bindings Library Xamarin C#)
- Navigate to Mozilla Maven and download
geckoview-nightly-93.0.20210823092315.aar
,geckoview-nightly-93.0.20210823092315-sources.jar
andgeckoview-nightly-93.0.20210823092315-javadoc.jar
files. - Move the 3 files to the
Jars
directory and include them in the project (you may need to unblock the files through the files properties). Here's what myJars
directory looks like: - Set Build Action for files as follows:
javadoc.jar
=>JavaDocJar
sources.jar
=>JavaSourceJar
and.aar
=>LibraryProjectZip
- Rebuild Solution (you should see at least 5 errors) for example:
BINDINGSGENERATOR : Syntax error
along those lines.
Solution
So I spent some time getting the binding working for this. I added the following to the Metadata.xml file to make it bind.
<metadata>
<remove-node path="/api/package[contains(@name,'org.mozilla.thirdparty')]" />
<remove-node path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/field[@name='mWindow']" />
<remove-node path="/api/package[@name='org.mozilla.geckoview']/class[@name='RuntimeSettings.Builder']/method[@name='newSettings' and count(parameter)=1 and parameter[1]]" />
<!-- Because of interfaces contain const fields Xamarin generate abstract classes, which clash with property name. Renaming properties -->
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='getHistoryDelegate' and count(parameter)=0]" name="propertyName">SessionHistoryDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='setHistoryDelegate' and count(parameter)=1 and parameter[1][@type='org.mozilla.geckoview.GeckoSession.HistoryDelegate']]" name="propertyName">SessionHistoryDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='getNavigationDelegate' and count(parameter)=0]" name="propertyName">SessionNavigationDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='setNavigationDelegate' and count(parameter)=1 and parameter[1][@type='org.mozilla.geckoview.GeckoSession.NavigationDelegate']]" name="propertyName">SessionNavigationDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='getPermissionDelegate' and count(parameter)=0]" name="propertyName">SessionPermissionDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='setPermissionDelegate' and count(parameter)=1 and parameter[1][@type='org.mozilla.geckoview.GeckoSession.PermissionDelegate']]" name="propertyName">SessionPermissionDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='getSelectionActionDelegate' and count(parameter)=0]" name="propertyName">SessionSelectionActionDelegate</attr>
<attr path="/api/package[@name='org.mozilla.geckoview']/class[@name='GeckoSession']/method[@name='setSelectionActionDelegate' and count(parameter)=1 and parameter[1][@type='org.mozilla.geckoview.GeckoSession.SelectionActionDelegate']]" name="propertyName">SessionSelectionActionDelegate</attr>
</metadata>
The remove-node
can be explained as:
- First
remove-node
removes some internals that you won't use anyways. So no need to create bindings for that. - Second one remove the field
mWindow
that for some reason was exposed publicly. I just removed it, we could also change visibility. - Third one I was not 100% sure how to fix. The
RuntimeSettings
class contains aNewSettings
method that differened betweenRuntimeSettings
and the builder in the generated code. I just opted to remove it. - The renaming of generated property names is due to a Java 8 feature where you can have
static
fields in a Interface in Java. This will generate an abstract class in the generated code. This class name clashed with the property name generated for the Setter/Getter for these delegates.
This makes the bindings build. I then added a simple sample project with the following code in the MainActivity to just show something on the screen:
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var geckoView = new GeckoView(this);
geckoView.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
SetContentView(geckoView);
var session = new GeckoSession();
GeckoRuntime runtime = GeckoRuntime.Create(this);
session.Open(runtime);
geckoView.Session = session;
session.LoadUri("https://blog.ostebaronen.dk");
}
}
Everything builds but now it crashes at runtime claiming to be missing org.yaml.snakeyaml.constructor.Constructor
. Not sure if this aar needs some additional dependencies, which need to be added when binding.
EDIT:
I checked the POM of the version of GeckoView you linked to, no traces of SnakeYAML. However, the latest version found (93.0.20210825095400) does have it:
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.24</version>
</dependency>
It also has some other dependencies it will need at runtime. Install the following NuGet packages in the binding project:
- Xamarin.AndroidX.Annotation
- Xamarin.AndroidX.Legacy.Support.V4
- Xamarin.AndroidX.Lifecycle.Extensions
Additionally, download the .jar
file for SnakeYAML 1.24 (the android one) and add as a EmbeddedReferenceJar
: https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.24/
After you've done this it runs!
Answered By - Cheesebaron
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.