So I have some classes that I have been storing in a local SQLite DB in a Xamarin Forms application. Works fine on UWP, Android, and iOS except for Release on a physical device. Keep getting JIT warnings. I've tried removing linking various ways to ensure it's getting compiled but no dice. The root of the issue seems to be within the usage of SQLite-Net-pcl nuget library. Does anyone have advice on how to ensure that code has been AOT compiled? My abstract class, maybe too abstract? Not sure.
public abstract class SqlRepositoryLite<T, TInterface> : IRepositoryLite<TInterface> where T : class, IDto, TInterface, new()
{
public IEnumerable<TInterface> Items => Connection.Table<T>();
Crash reports:
SIGABRT: Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_CharacterItem_int (PFAssistant.Core.Services.CharacterItem,int)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information.
Stacktrace:
FastColumnSetter+<>c__DisplayClass2_0`2[ObjectType,ColumnMemberType].<CreateTypedSetterDelegate>b__0 (System.Object o, SQLitePCL.sqlite3_stmt stmt, System.Int32 i)
SQLiteCommand+<ExecuteDeferredQuery>d__12`1[T].MoveNext ()
List`1[T].AddEnumerable (System.Collections.Generic.IEnumerable`1[T] enumerable)
System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) <0x1052cce30 + 0x0021f> in <25bf495f7d6b4944aa395b3ab5293479#0dcf7231fb8229d159bd9a1419156fe3>:0
Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source)
SQLiteCommand.ExecuteQuery[T] ()
Update: Would seem updating Sqlite-net-pcl to v1.8.116 was a major part of my issue, had issues with 1.6.292 as well. 1.7.335 worked perfectly.
I found the same to be the case today. Downgrading to 1.7.335 is the solution.
Related
Our Xamarin Android app relies heavily on some older components in MvvmCross 4.4.0 and so has not been updated to modern versions.
We used the guide found here to modernise just enough to get over the API 29/Android 10 hurdle:
https://blog.ostebaronen.dk/2020/08/old-mvvmcross-and-android-10.html
We're now at the API 31/Android 12 hurdle and, whilst everything builds and executes fine with API 31 when running on Android 11 and below, Android 12 is crashing.
The MainActivity is initialising with a null ViewModel because the LayoutInflater (already corrected for API 29) cannot retrieve the current binding context with MvxAndroidBindingContextHelpers.Current().
Nothing in the Android 12 behaviour changes guides gives an indication as to what is causing this change. We have also reviewed changes in modern versions of the MvvmCross.Binding source and can't see any obvious changes that correct this behaviour.
This is the code in LayoutInflater.cs where the problem first surfaces:
public override View? Inflate(int resource, ViewGroup? root, bool attachToRoot)
{
// Make sure our private factory is set since LayoutInflater > Honeycomb
// uses a private factory.
SetPrivateFactoryInternal();
// Save the old factory in case we are recursing because of an MvxAdapter etc.
IMvxLayoutInflaterHolderFactory? originalFactory = _bindingVisitor.Factory;
try
{
IMvxLayoutInflaterHolderFactory? factory = null;
// Get the current binding context
var currentBindingContext = MvxAndroidBindingContextHelpers.Current();
// currentBindingContext is null on Android 12, not on Android 11 and below
if (currentBindingContext != null)
{
factory = FactoryFactory?.Create(currentBindingContext.DataContext);
// Set the current factory used to generate bindings
if (factory != null)
_bindingVisitor.Factory = factory;
}
// Inflate the resource
var view = base.Inflate(resource, root, attachToRoot);
// Register bindings with clear key
if (currentBindingContext != null)
{
if (factory != null)
currentBindingContext.RegisterBindingsWithClearKey(view, factory.CreatedBindings);
}
return view;
}
finally
{
_bindingVisitor.Factory = originalFactory;
}
}
Any insight as to potential causes of the problem would be welcome, even if it's a concrete reason why MvvmCross 4.4.0 is simply no-longer viable on Android 12.
Thanks very much.
Update: We have now successfully updated to MvvmCross 5.0.1 and the problem still remains (which we expected). Our dependency is on MvvmCross.Droid.Shared, which is removed from newer versions. Can anybody recommend a guide on migrating away from MvvmCross.Droid.Shared please, as it doesn't appear to be mentioned in the upgrade guides other than to just remove it?
Update 2: Switching out the LayoutInflater for the one from MvvmCross 9.0.1 makes no difference. We've done this simply to rule that out. The issue feels like it related more to Binding.
The issue was not directly related to MvvmCross, but rather a change in Android 12 behaviour that prevented initialisation in a manner that meant ViewModel binding wasn't happening despite the rest of the code executing.
The resolution was to add some specific AndroidX initialisation lines to the AndroidManifest:
<provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup">
<meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" />
</provider>
...and to
Update Xamarin.GooglePlayServices NuGet packages
Add Xamarin.AndroidX NuGet packages
Increase the minSdkVersion from 19 to 21
my xamarin android app, which was working fine, started to crash on each launch with this exception.
The app is built from appcenter's build service, as it always has. If i build it locally in Debug or Release mode, it launches fine. Using a device with Android 7.
Did anyone encountered this exception and knows what to do ?
Ty !
18828 W monodroid: Calling into managed runtime init
E mono :
E mono : Unhandled Exception:
E mono : System.TypeInitializationException: The type initializer for 'Android.Runtime.UncaughtExceptionHandler' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
E mono : Parameter name: method
E mono : at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) <0x56d026b4 + 0x00d74> in :0
E mono : at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) <0x56d03594 + 0x0001f> in :0
: at Android.Runtime.UncaughtExceptionHandler..cctor () <0x57d908a4 + 0x0003f> in :0
: --- End of inner exception stack trace ---
: at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
: at Android.Runtime.JNIEnv.Initialize (Android.Runtime.JnienvInitializeArgs* args)
-- EDIT
All AOT/LVVM/Concurrent garbage collector/proguard/multidex options are enabled
-- EDIT 2
Source code of error: https://github.com/xamarin/xamarin-android/blob/master/src/Mono.Android/Android.Runtime/UncaughtExceptionHandler.cs
static UncaughtExceptionHandler ()
{
var mono_UnhandledException = typeof (System.Diagnostics.Debugger)
.GetMethod ("Mono_UnhandledException", BindingFlags.NonPublic | BindingFlags.Static);
mono_unhandled_exception = (Action<Exception>) Delegate.CreateDelegate (typeof(Action<Exception>), mono_UnhandledException);
var ad_due = typeof (AppDomain)
.GetMethod ("DoUnhandledException",
bindingAttr: BindingFlags.NonPublic | BindingFlags.Instance,
binder: null,
types: new []{typeof (UnhandledExceptionEventArgs)},
modifiers: null);
if (ad_due != null) {
AppDomain_DoUnhandledException = (Action<AppDomain, UnhandledExceptionEventArgs>) Delegate.CreateDelegate (
typeof (Action<AppDomain, UnhandledExceptionEventArgs>), ad_due);
}
}
So it seems either mono_UnhandledException is null or AppDomain_DoUnhandledException is null.
Will try to upgrade or downgrade mono version in appcenter. It should be wrong.
-- EDIT 3
AppDomain.cs has changed recently in mono:
https://github.com/mono/mono/commits/c1cbe060f617707258fd5111fd5ffd7ccd581899/mcs/class/corlib/System/AppDomain.cs
But DoUnhandledException has not changed.
-- EDIT 4
Works fine when built/published locally. So the problem is specific to appcenter.
AppCenter has recently released Mono 5.8 bundled with Xamarin.Android 8.2 (which supports TargetFrameworkVersion: 8.1), in order to use it, please change your branch configuration -> Save&Build.
Also filed the issue for investigation by Xamarin.Android team.
In my case, the issue was caused by using Android SDK 8.1 which App Center doesn't support yet.
I had to downgrade to SDK 8.0 and now build works fine.
App Center team promised to add support to SDK 8.1, but they don't have an ETA yet.
we faced the same issue with jenkins and msbuild. rollback to 8.0 as target and disable 'use latest' works. locally, with 'use latest', build tools 26.0.3 and msbuild on macos app works like a charm. not sure what build tools installed on jenkins.
I'm having the same issue in App Center. My Android app is set to target android 8.1 (latest) and builds ok in App Center but when running "launch test" it fails.
The app is running fine locally in Debug and Release modes.
I tried disabling launch test so the app can be distributed to my collaborators. When any of my collabortors download the app and use it, the app doesn't work.
I built it using VSTS and distributed through App Center to my collaborators and they said the app is working, so I can conclude it's an App Center build issue.
I didn't try to build my app using Android 8.0 because some nuget packages only work on Android 8.1 and I didn't have time to downgrade them.
I'm new to Xamarin. While Building my project, I came across this Warning. I tried to look for its solutions, but none of them resolved this issue.
Severity Code Description Project File Line Source Suppression State
Warning Exception of type 'System.OutOfMemoryException' was thrown.
at Microsoft.Cci.Pdb.MsfDirectory..ctor(PdbReader reader, PdbFileHeader head, BitAccess bits)
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, BitAccess bits, Boolean readAllStrings)
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Boolean readAllStrings)
at Pdb2Mdb.Converter.Convert(String filename)
at Xamarin.Android.Tasks.ConvertDebuggingFiles.Execute()
Thats is related to RAM being not enough .
You can try increasing virtual memory .
If you are working on MAC - you need 8 gb ram that should do .
on Windows when we were getting that problem we had to increase that to 16 gb to get rid of it .( vs and android studio both were there though) .
Since moving to Xcode 8 and iOS10, my metal based app fails to run at all. On launch I get the error: "Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED"
This appears two to three times in the console before crashing due to a MTLComputePipelineState not being successfully created and throwing an error when calling the MTLDevice function makeComputePipelineState(function:). The only changes I have made to the project is to update to Swift 3.0, but the console seems to imply a compiler error, which due to the crash I'm assuming is down to some metal code not compiling properly.
Any help would be appreciated, this is ageing me prematurely.
UPDATE:
I've located the line causing the trouble in the .metal file:
int gi1 = permMod12[ii+i1+perm[jj+j1+perm[kk+k1]]];
permMod12 is a static constant array declared as:
static constant int permMod12 [512] = {7,4,5,7...}
perm is similarly static and constant:
static constant int perm [512] = {151,160...}
The variables ii, i1, jj, j1, kk and k1 are all integers calculated in the same kernel.
The kernel is quite large so I'll post a link to the GitHub location. It's the functions called simplex3D and simplex4D that are causing the issue. These are very similar so only focus on one of them, they are carbon copies but 4D has another stretch of variables running (ll, l1, l etc).
The issue certainly seems to be with looking up these arrays with calculated variables as when I change the variables to simple literals there is no error.
The kernel needs to be executed in order to get the error to occur.
Any help with this new info would be great.
I also encountered the same error: "Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED". The issue was resolved. It stemmed from attempted use of 'threadgroup bool' type variables. Refactoring the code to use 'threadgroup short' variables in place of the boolean resolved the error. (Could not find in the Metal Version 2 specification if bool type is or is not a valid threadgroup type.)
I've encountered this situation, and it seems that there is no unique solution to solve this problem. In my case, the problem was occurred when a texture that uses a normalized coordinate sampler also uses read() function. When I switch read() function to sample() this weird error was removed. I hope your problem were solved already.
I have been working in storyboard designing app for IOS. No code, besides automatically generated one is written. After reopening storyboard file in Xamarin I got following error:
System.AggregateException: One or more errors occured ---> MonoTouch.Design.Client.DesignerRemoteException: System.ArgumentNullException: Argument cannot be null.
Parameter name: key
at System.Collections.Generic.Dictionary`2[MonoTouch.UIKit.UIImage,System.String].set_Item (MonoTouch.UIKit.UIImage key, System.String value) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:216
at MonoTouch.Design.Server.ImageResourceManager.SetImage (System.String name, MonoTouch.UIKit.UIImage value) in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Server/ImageResourceManager.cs:79
at MonoTouch.Design.Server.SessionController+<PostImageResource>c__AnonStorey3.<>m__0 () in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Server/SessionController.cs:167
at MonoTouch.Design.NativeExtensions+<SafeInvokeOnMainThread>c__AnonStorey0.<>m__0 () in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Server/Util/NativeExtensions.cs:378
at MonoTouch.Design.Client.ServerProcessConnection.SendRequest (MonoTouch.Design.CommandRequest req, Boolean throwIfNotRunning) [0x0007f] in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Client/Connection/ServerProcessConnection.cs:195
at MonoTouch.Design.Client.ServerProcessConnection.SendRequest[Object] (MonoTouch.Design.CommandRequest req, Boolean throwIfNotRunning) [0x00004] in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Client/Connection/ServerProcessConnection.cs:202
at MonoTouch.Design.Client.ServerProcessConnection.PostResources (MonoTouch.Design.DesignSession session, MonoTouch.Design.ImageResource[] resources) [0x0003f] in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Client/Connection/ServerProcessConnection.cs:132
at MonoTouch.Design.Client.IPhoneDesignerSession+<SendImageResources>c__AnonStorey13.<>m__1 () [0x00019] in /Users/builder/data/lanes/1089/7d45bbe2/source/md-addins/Xamarin.Designer.iOS/MonoTouch.Design.Client/IPhoneDesignerSession.cs:1329
at System.Threading.Tasks.TaskActionInvoker+FuncInvoke`1[System.Object].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in /Volumes/build-root-ramdisk/mono-3.6.0/mcs/class/corlib/System.Threading.Tasks/TaskActionInvoker.cs:242
at System.Threading.Tasks.Task.InnerInvoke () [0x00031] in /Volumes/build-root-ramdisk/mono-3.6.0/mcs/class/corlib/System.Threading.Tasks/Task.cs:548
at System.Threading.Tasks.Task.ThreadStart () [0x000d0] in /Volumes/build-root-ramdisk/mono-3.6.0/mcs/class/corlib/System.Threading.Tasks/Task.cs:438
Can anybody help to figure out what this means?
As far as I can tell the error is caused by the following:
iOS Designer opens the StoryBoard and tries to parse the XML inside.
Upon parsing it calls MonoTouch.Design.Server (which probably runs code against Xcode for rendering the XML). While doing so it encounters a ViewElement containing a UIImage. So then it tries to setup the UIImage using parameters stored in a Dictionary (filled using the same XML). When it tries to access that Dictionary for the parameters to yield to UIImage it puts in a 'null' for the key and this causes your error.
Now I don't know exactly what in your Storyboard causes this error as you haven't provided the Storyboard-file in question (nor can I guarantee I could find that error if you had), but you can try some of the following things to try and resolve the issue.
Try and open the Storyboard in Xcode instead of iOS Designer. It sometimes manages to fix corrupt Storyboards that iOS Designer can't handle.
Open the Storyboard in XML-view and have a look at the elements that have UIImages in them. Try and see if anyone of them has a 'strange' name, source, value or something.
Post the Storyboard here and see if anyone else can spot the error
I encountered a similar scenario in that the error message started exactly as in the original post. I could not open the storyboard both in Visual Studio 2015 and in Xamarin Studio 5.10.3 (build 51)
After spending some time in comparing the changes to the .csproj file i figured out that the image for ipad caused this issue for me. I do not know the actual reason for the original post but for me, i had an image to be used as the app logo for ipad and i had named it as "imagename#ipad.png". It turns out this freaks out the designer even though XCode 7 perfectly opens the storyboard.
Finally i renamed the image as "imagename~iPad.png" and that did the trick. Both VS 2015 and XS 5.10.3 are happy to open the storyboard!
Documentation from Xamarin below for working with images
https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_images/sizes-and-filenames/