PlatformEffect in .NET Standard lib doesn't get resolved - xamarin.forms

I have implemented a Xamarin.Forms effect and spiked i successfully but I now need to create a proper NugGet package to use it as a component in my projects.
I added a .NET Standard lib for the RoutedEffect implementation. Then created three platform-specific lib projects for iOS, Android and UWP. To try everything out I then created a new Xamarin.Forms app with a .NET Standard "common" lib that references the RoutedEffect´s .NET Standard lib. Finally, from the iOS app I reference both the RoutedEffect's lib and the (iOS) PlatformEffect implementation lib.
The problem is that the PlatformEffect never gets instantiated. I tried resolving it from the .NET Standard common lib, just to see what's going on, and I just get back a NullEffect. For sake of sanity I then tried moving the code for the iOS PlatformEffect from its iOS lib into the iOS app. This works. But I have no idea why it won't work when implemented in the iOS lib, when referenced from the iOS app.
Am I missing something?

Ok, this was a bit embarrasing, and an example why you shouldn't code late in the night I guess. :-/
After a good night's sleep I realized the PlatformEffect lib, which consist of one effect only, was only referenced from the iOS project but none of the lib's types was actually referenced and, so, the .NET linker won't link the lib.
Just adding a reference to the platform Effect type solved the problem and it works fine.
Please move on ... :-)

Related

How use iOS AppTrackingTransparency.ATTrackingManager from cross-platform PCL?

So yesterday this line:
ATTrackingManager.RequestTrackingAuthorization((status) => {
if (status == ATTrackingManagerAuthorizationStatus.Authorized)
{
}
was working code (in my cross-platform Xamarin.Forms PCL).
Today xamarin.ios received an update.
In the PCL project, the tracking manager is not found anymore. Intellisense doesnt know what it is anymore and I cannot debug the app.
It is recognized in the xamarin.ios project, but I need to access it from my PCL.
Anyone having the same issue and / or has already found a solution?
How can I rollback to xamarin.ios before the one I received today?
Don't need to rollback. As a test, I updated
Visual Studio (which also updated Xamarin.iOS).
XCode to 14.5.1.
Then I added a line of code to an existing Xamarin Forms solution, that referenced AppTrackingTransparency.ATTrackingManager. This was recognized as valid code. I Also tried just ATTrackingManager, and Intellisense correctly told me I needed using AppTrackingTransparency.
So its there now.
That namespace+classname is specific to iOS, so must be referenced from the iOS-specific project. (If it previously was referenceable in the PCL, that was probably a bug that has since been corrected; such code would break on any other platform.)
First step:
In your iOS project, write code that references that class.
Second step:
You need to know how to use your custom iOS code from the cross-platform Xamarin Forms PCL.
I won't repeat that here - there are multiple Q&As on that topic.
google "stackoverflow xamarin forms call platform specific code".

Migrating Xamarin.Forms Android app to AndroidX support packages

I have a Xamarin.Forms Android project, am I'm trying migrate from the old Android support packages to AndroidX. The migrate seems to work, and I end up having to add a reference to the AndroidX media package during compile.
The issue is that when I try to actually run the app, I get the exception
System.InvalidCastException: 'Unable to convert instance of type 'Android.Widget.RelativeLayout' to type 'AndroidX.AppCompat.Widget.Toolbar'.'
from the Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate. My MainActivity class subclasses FormsAppCompatActivity and MainActivity's OnCreate immediately calls the base OnCreate. Visual Studio says the exception is from external code, so it doesn't show me anything.
The OnStart and OnResume overrides in my MainActivity are called and finish fine (its only one line of code configuring the CrossCurrentActivity plugin being used.
I'm at a loss as to how to track down the problem. I suspect the issue is somewhere in one of the packages I'm using, my main suspect being the Xam.Plugin.Iconize since it hasn't been updated for a while, but we rely on it and I'm not really sure how to prove where the issue is.
I recently migrated to AndroidX and published the app. Users have been reporting a lot of crashes on start. I'm still figuring it out. Weird part is that, it works fine on some devices but crashes on some others.
I have noticed a few files in Android project still refer to the old 'Android Support' lib. Make sure you change them manually to AndroidX.
Check the Toolbar.xml and Tabbar.xml (Android proj>Resources>Layout). I had this in my app, which was still using android.support.v7......
I suggest to check in all the files and update manually where ever required.

How to include Android.Support.v4 in Xamarin Forms (iOS)?

I am using Visual Studio For Mac. My Xamarin Forms project is quite large and contains many content pages. Some of them will be only used in android project and some of them only used in iOS project. There is no problem when I compile the project into android. However, when I want to compile the project into iOS, it seems like did not accept anything related to android. Please refer to the screenshot. There is no way I can include the android specialised reference and compile into iOS project. So, any idea to deal with this? Maybe there is a way to force build the iOS project no matter what? The error from the screenshot is from the page that will be only used in android. So what I can do for now is delete the page when I want to compile as iOS and recreate the page when I want to used it for android. But there are plenty of them, it is too heavy for me to do this every time. Please help.
You can't call platform specific APIs at the .NET standard libraries that are used to host Xamarin.Forms code by default.
Basically you have those options:
1) using shared project instead of library and using conditional compiling (easier but it is now not available as the option when creating the project)
2) using dependency injection.

Is Prism 6.3.0 tied to an older version of Unity (I can't seem to upgrade)

I've got a WPF App using the latest version of Prism for WPF (6.3.0) and Unity. Just a few modules. It works great.
When I manage NuGet packages for my solution, it tells me that there is a new version of Unity (5.4.0) available. Unfortunately, if I try to update to that version, I can no longer build.
It's pretty clear to see why: Upgrading unity via this method removes all references to it (Unity) from my project. Specifically the following 3 references completely disappear from all my projects without any replacement:
Microsoft.Practices.Unity
Microsoft.Practices.Unity.Configuration
Microsoft.Practices.Unity.RegistrationByConvention
(The Prism references remain, of course)
Error messages tell me that IUnityContainer is defined in an unreferenced assembly (Microsoft.Practices.Unity. 4.0.0.0). Given that it removed those assemblies, this all makes sense.
If I then try to go looking to add Unity back in, the Add Project Reference dialog cannot even find Microsoft.Practices.Unity when I search for it.
Now this isn't that big of a deal. I didn't need to upgrade. and it's easy for me to revert back. But I want to understand why this is failing for future reference.
Does this mean that Prism is tied to the older version of Unity and I just shouldn't upgrade?
Does this mean that types have moved to different namespaces and I need to make some other fix?
Some other reason?
Among the Unity 5 updates included a change of namespaces which as you noticed was a major breaking change. There are no plans for Prism 6 to support Unity 5, however the current Prism 7 previews (which is available for WPF) have updated both the Common Service Locator and Unity.
https://www.nuget.org/packages/Prism.Unity/7.0.0.336-pre

Xamarin.Forms - Xamarin.Forms.Maps broken references in Droid Project

I need to implement Map functionality into an application that I'm building.
And I was folliwing this guide.
I downloaded the package and did all of the configuration.
I haven't implemented the Map class into my project yet, I only did the configuration required for both platforms (Android and iOS).
The Portable project and the iOS project are fine, the problem here is the Android project.
It has some broken references, these ones:
And when I try to compile the Android project, I get this error and these warnings:
Can anybody give me a hand? Thanks in advance.
EDIT:
As a sidenote, I'm using the Sdk installed by Android Studio, and that one has the latest Google Play Services installed.
UPDATE:
I just upgraded the version of my Xamarin.GooglePlayServices one by one (the one listed up there in the first image) for some reason it downloaded a really old version of those. So I just upgraded them, and it seems those references are fine now.
But I still get the error:
The "ResolveLibraryProjectImports" tasks failed unexpectedly.
SOLUTION:
I unloaded the Android project, added this:
<UseShortFileNames>True</UseShortFileNames>
To every property group in the .csproj file.
Load my android project back, and it all worked fine now.

Resources