Windows Universal app with Android binding error - android

I have created a simple universal app targeting Windows Phone 8.1 & Windows 8.1 in Visual Studio 2013.
I added an android project and implemented MvvmLight.
ViewmodelLocator, viewmodels & messaging all work fine.
Databinding also works for the windows projects.
When I try adding databinding within the android project - at run time I get an error Property not found: Text
Button bindingButton = FindViewById<Button>(Resource.Id.button1);
var vm = ViewModelLocator.Main;
this.AddBinding(() => vm.AsyncCompleted,
() => bindingButton.Text,
BindingMode.TwoWay);
Has anyone else encountered this?

OK - solved it myself.
I was originally following an example from the mvvm light home page which doesn't seem to work with an Android project within a Universal App.
The answer is to specify the Actual control to add the binding to and pass the fully qualified View Model property to the binding:
Button bindingButton = FindViewById<Button>(Resource.Id.button1);
bindingButton.AddBinding(
() => ViewModelLocator.Main.AsyncCompleted,
() => bindingButton.Text,
BindingMode.OneWay);

Related

KMM - Unresolved reference: platform for IOS application

Hellow.
I have a trouble with template KMM application. It got an error after I created new KMM application - in shared IOS app module it cannot find package platform. It's on kotlin. Adroid app works well.
Need to say, that I works on window by Android studio. I know there are troubles to start IOS app on window, but I do not want to start or build app - I want to just it find the reference platform.
I tried to find some dicisions. There are the same questions, but nobody can answer them.
Code with trouble:
import platform.UIKit.UIDevice // here there is the error
actual class Platform actual constructor() {
actual val platform: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}
This question is a bit strange: how do you think iOS application will compile and work on a Windows computer?
To make KMM work on both OS you need a Mac. This is the reason why you are not able to find "platform.UIKit.UIDevice" on your machine.

Breakpoints is not hitting while debugging a .NET MAUI android application

I have been working on a MAUI android application and when debugging, the breakpoints is not hitting and the application enter in a break state. But for windows app it works well.
I think this is an issue with the .NET 6 Android Tooling in visual studio 2022. Is there any solutions for this problem ?
Here is a few steps I did to make things work with debugging MAUI Android apps. I was able to debug and get my regular exceptions and hit breakpoints after this.
Add this code to Android platform main activity OnCreate method
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Then this hander method in the same class
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ System.Diagnostics.Debug.WriteLine(e.ToString());}
Reset Your Exceptions for CLR. Shortcut is (Ctrl+Alt+E).
Just double-click on the CLR Exceptions checkbox to reset.
Disable Debug Your Code Only in Options
I was also having problems debugging some projects. (Preview 17.1.0) The ones that were failing had the following project settings.
<PropertyGroup>
<TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks> ...
Moving Android first fixed my problem
<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks> ...
I had the same problem and it is now working, try this:
Windows -> Settings -> Update & Security -> For Developers -> Developer Mode - On
Solution Properties -> Deploy - On
Visual Studio -> Tools -> Options -> Xml Hot Reaload -> Disable all
The you can just set your project has startup and run it.

null is not an object (evaluating 'RCTToastAndroid.SHORT')

I am attempting to convert my react-native project into an expo project, one small issue I've encountered is when I run the expo project I get an error as such
null is not an object (evaluating 'RCTToastAndroid.SHORT')
After doing some research online on how to fix this problem a user requested that a problem like this can simply be resolved by removing the Android part of RCTToastAndroid.SHORT this user stated that RCTToast is universally compatible with both iOS and Android. However when I do this I receive an error saying null is not an object (evaluating 'RCTToast.SHORT')
What can I do that will help ease the transition from my react-native project to an expo project?
All apps created with create-react-native-app, are compatible with Expo CLI without changes.
Ref link:- https://github.com/react-community/create-react-native-app/blob/master/CHANGELOG.md#upgrading-from-1140-to-201
only do like this
import {ToastAndroid}from 'react-native '
return ToastAndroid.show("some error msg", ToastAndroid.LONG);
I had the same exact problem.
Check to see if you've imported a library called 'react-native-simple-toast'. Remove it from your dependencies.
According to this issue:
this library has a custom native module for ios, and expo does not support that. This lib will not work with expo
it will only work with a bare React Native project.
If you do need to use Toasts
Here's a library that will work with Expo on both Android and iOS. The only downside is that it's pure Javascript.
You can use it like this:
import Toast from 'react-native-root-toast'
Toast.show('Your message here', {
duration: Toast.durations.SHORT,
position: Toast.positions.BOTTOM,
shadow: true,
animation: true
});

Prism Xamarin.Forms monoandroid81 Add a reference to "MonoAndroid

I keep getting this error. (I'm using Android v8.1 and Prism default template)
Severity Code Description Project File Line Suppression State
Error Your project is not referencing the "MonoAndroid,Version=v8.1"
framework. Add a reference to "MonoAndroid,Version=v8.1" in the "frameworks"
section of your project.json, and then re-run NuGet restore.d#
PrismHelloWorld.Android
So I went into my project.assets.json and change the "monoandroid71" to "monoandroid81"
"originalTargetFrameworks": [
"monoandroid71"
...
"monoandroid71": {
"projectReferences": {
...
"frameworks": {
"monoandroid71": {
I also changed
"projectFileDependencyGroups": {
"MonoAndroid,Version=v7.1": [
and ...
"targets": {
"MonoAndroid,Version=v7.1": {
I hit save and rebuild and it works absolutely fine! The problem is something is editing the json file and turning it all back to 71 and 7.1. I am not sure what is doing it but I will hit built and see the error again, about me needing a reference to v8.1.
Has anyone encountered this issue before?
Go to Android project Options -> Application -> Compile using Android version: (Target framework) and choose Android 8.1 (Oreo). Try different options
I just had the same problem on MvvmCross with Xamarin and I did your solution (changing "monoandroid71" to "monoandroid81" and "v7.1" to "v8.1") but it reverts back after closing and reopening the solution. What I did was do the same thing and do a "Restore NuGet Packages" at the end.
got the same issue, and able to fix it using below option,
Change the target version and rebuild.
I had the same issue, what I did was just restarted VS, and its back to normal
I resolved it by:
Right click Android project => Properties => Application => Compile using Android version => Android 7.1
Clean and Build project => build success, and restart IDE.
Right click Android project => Properties => Application => Compile using Android version => Android 8.1
Clean and Build project => build success
File obj/project.assets.json updated to "MonoAndroid,Version=v8.1"

Xamarin Forms fails to create an instance of DI container

Using Visual Studio 2017.
Created the default Xamarin Forms project (.net standard 2.0 + android). No changes in project configuration, Debug mode.
Compile -> Build -> Success (simple page with a standard text).
Added Unity/Autofac and created an instance of the container in App.
In Unity:
Object reference not set to an instance of an object
Similar in AutoFac
p.s. tried the approach to skip linking assembly System.Core
upd.1
This is absolutely standard solution with the only 1 line of code:
public App ()
{
InitializeComponent();
var c = new UnityContainer(); //this is the line for Unity
MainPage = new App2.MainPage();
}
The scenario with Autofac is similar. But it fails on RegisterType with exception Target of Add is null (NullReferenceException)
upd.2
This fails both in Release and Debug mode
This does not fail in simulator!
This fails during any kind of execution on phone directly (inculding Xamarin Live)

Categories

Resources