Xamarin Android Binding Library Custom Namespace Not Recognized - xamarin

I am creating a Xamarin Android binding library for an existing JAR that contains a single class and following the Xamarin binding library documentation, I am able to successfully rename the namespace using:
<attr path="/api/package[#name='com.company.blah']" name="managedName">Company.Blah</attr>
I also confirmed the namespace is changed in the generated class in the 'obj/Debug' folder:
namespace Company.Blah {
// Metadata.xml XPath class reference: path="/api/package[#name='com.company.blah']/class[#name='NativeClass']"
[global::Android.Runtime.Register ("com/sprylab/android/widget/TextureVideoView", DoNotGenerateAcw=true)]
public partial class NativeClass
{
...
}
}
I face two problems:
I am unable to reference NativeClass from a sample Android project. It's like to doesn't see the namespace at all. The binding project built successfully without errors.
If I remove the package namespace rename setting, it also builds successfully and I am then able to reference it in my sample project but it requires that I fully qualify the class name anywhere it is used:
private com.company.blah.NativeClass nativeClass;
I'm hoping if I can fix #1, then #2 will not show up again. If so, I'm also curious how you prevent fully qualified class names from showing up?

Going into the project settings of the binding library project and clearing the box to the right of the assembly name seemed to do the trick. Looking inside the csproj directly, it is the root namespace.

Related

Mapbox Navigation Xamarin Bindings - AAR errors "does not implement interface IComparator.Compare"

I have created all my .gradle files (.jar and .aar) through Android Studio.
The .jar files compile to .dll files through the android bindings in Xamarin without any issues - and I can expand them in object explorer Visual Studio when including them as references.
My problem is with the .aar files.
I have the mapbox-android-core-1.4.0.aar file from the gradle in my Jars folder in Visual Studio.
The build action is set to "LibraryProjectZip" and under references I have included Xamarin.Android.Support.v7.AppCompat which then included all other android support dependencies.
The Android Compile version is Android 9.0
Android class parser: class-parse
Android codegen target: XAJavaInterop1
When I build i get the following error:
Error CS0535 'FileUtils.LastModifiedComparator' does not implement interface member 'IComparator.Compare(Object, Object)'
The official Xamarin troublehsooting says I must add the managed return to metadata which I did as follows:
<attr path="/api/package[#name='com.mapbox.android.core']/class[#name='FileUtils']/method[#name='FileUtils.LastModifiedComparator']" name="managedReturn">java.lang.Object</attr>
With this added it still has exactly the same error, so I am not sure where I am going wrong.
Do I need to add a partial class to Additions or is the attr> above sufficient - just using the wrong information inside it, or am I missing what the error is in the first place?
Error CS0535 'FileUtils.LastModifiedComparator' does not implement interface member 'IComparator.Compare(Object, Object)'
To fix this issue, try to add a partial class declaration for 'LastModifiedComparator' class and explicitly implement IComparator.Compare(Object, Object):
public partial class DeviceService
{
public void Compare(object a, object b)
{
...
}
}
In your case, the method name in <attr ...> tag should be Compare instead of the 'LastModifiedComparator' method.
Check the tutorial:
https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/troubleshooting-bindings#possible-causes-6
Similar issue:
error CS0535 Class does not implement interface member

Xamarin Android Layout Resources in library project not included in Application

I have a Xamarin Android library project which is referenced by an Android application project.
The library project has layout files which need to be used by a library project component. The Resource.designer.cs file seems to be generated properly. The layouts are marked as Android Resources. Yet at runtime the resources are not there. Trying to access them just returns 0.
After reading all the SO questions on the topic, I am convinced this should work, but so far it doesn't. Ideas?
Create the Android Class Library.
Create a layout folder in this class library and create a layout in this folder.
Add the code in your xamarin android app.
var btn_Load = FindViewById<Button>(Resource.Id.btn_LoadLibraryLayout);
btn_Load.Click += delegate
{
SetContentView(ClassLibrary1.Resource.Layout.library_layout);
};
I create a button to open the layout in class library.
Result:
You could download from the ClassLibrary_layout folder of GitHub for reference.
https://github.com/WendyZang/Test.git
Updated:
If you want to get the resource identifier, you need the package name of this class library. First, we could not get the package name in AndroidManifest.xml file or properties, because the class library does not have it.
You could get it from the steps below.
Create a activity in class library. And get the package name with the code.
var PackageNname = Application.Context.PackageName;
You could also get the resource identifier in this activity.
var resId2 = Resources.GetIdentifier("library_layout", "layout", PackageNname);
Result:
The paskage name is same to the app1 I provided.
Package Name: com.companyname.app1
You could also use the code directly in app1 activity.
int resId2 = Resources.GetIdentifier("library_layout", "layout", "com.companyname.app1");

Null exception namespace App in Xamarin for UWP

I am developing UWP app in xamarin. The application works on IOS, Mac , Android, Windows. I have created UWP project in it according to the tutorial given in developer.xamarin.com. But it giving error saying Accessibility.App namespace not found.
Here is my code:
namespace Accessibility.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
this.LoadApplication(new Accessibility.App());
}
}
}
According to your description, the app can't see Accessibility.App. As you claim that Android and iOS projects work there are two things that can cause the problem:
you don't have the reference to your Shared/PCL project in your UWP project (most likely).
you have possibly changed the namespace / class name in the Shared/PCL project to something else than Accessibility.App
This is usually caused by missing reference to the shared project or class library where Xamarin.Forms App class resides. From the description this project should be called Accessibility.
Right-click the UWP project select Add, Reference... then in Solution tab select the Accessibility project.
Also it might happen that the UWP project didn't pick up on the reference, so restarting Visual Studio might help as well.
If all fails, you can try to use class name binding with using. On top of the source code file add:
using FormsApp = Accessibility.App;
And then in code use:
this.LoadApplication(new FormsApp());

Xamarin Sport App - Unknown Identifier

I am looking at their sample application for sports leagues found here: https://github.com/xamarin/Sport
I put a breakpoint here:
But when I hover/do a quick watch on athleteId and/or registraitonComplete, I get
Unknown identifier: Settings
The thing is, I can step into Settings so I know it can find it – heck it shouldn’t compile without it…
No answers yet, here is the solution for those who are still looking for
Settings is a static class, somehow Visual studio(Xamarin) does not recognize the static class whose actual path and namespace does not match. So, to access Settings whose namespace is like below, you need to use Sport.Mobile.Shared.Settings.
namespace Sport.Mobile.Shared {
public static class Settings
This applies to any static class you use in your project.

Problem while including custom framework in Project

I am trying to learn how to create custom frameworks and use them in a project in cocoa, so I began with a simple custom framework named - SimpleFramework.
It contains one class with only one class method:
// class name: SimpleClass, role: Public
+ (void)displayMessage{
NSLog(#"Hello World");
}
I also set its Installation Directory path to - #executable_path/../Frameworks then compiled it.
I included it in another project - SimpleTest, using following steps-
Dragged SimpleFramework.framework into Frameworks folder in project. Also selected Copy items to destination group's folder and Add To Targets check box.
Created a New Copy Files Build Phase. Selected its destination as Frameworks.
Dragged SimpleFramework.framework into it.
Problem is, when I am trying to import
SimpleClass.h in SimpleTestAppDelegate
class, it is giving this error message
on compilation-
SimpleClass.h: No such file or
directory.
Can anyone suggest me if I am doing anything wrong?
Code for application can be found here- Sample code link
Thanks,
Miraaj
I found its solution. I was missing this line:
#import "SimpleFramework/SimpleClass.h"

Resources