WHEN LINKING IS SET TO SDK AND USER

kefikefi Member ✭✭

Problem is getting in Mainactivity.cs file on this line:

LoadApplication(new App(new AndroidInitializer()));

Unity.Exceptions.ResolutionFailedException: Resolution of the dependency failed, type = 'Prism.Modularity.IModuleCatalog', name = '(none)'.
Exception occurred while: while resolving.
Exception is: ArgumentNullException - Value cannot be null.

Parameter name: method

At the time of the exception, the container was:
Resolving Prism.Modularity.ModuleCatalog,(none) (mapped from Prism.Modularity.IModuleCatalog, (none))
Resolving Prism.Modularity.ModuleCatalog,(none)

My mainACTIVITY.CS FILE IS

using Acr.UserDialogs;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Plugin.CurrentActivity;
using Prism;
using Prism.Ioc;
using Lottie.Forms.Droid;
using System;
using Android.Content;

namespace Kefi.Droid
{
[Activity(Label = "Kefi.Android", Icon = "@mipmap/ic_launcher", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
private Context Context { get; set; }
protected override void OnCreate(Bundle bundle)
{

        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        Rg.Plugins.Popup.Popup.Init(this, bundle);
        base.OnCreate(bundle);
        UserDialogs.Init(this);
        ZXing.Net.Mobile.Forms.Android.Platform.Init();
        ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
        CrossCurrentActivity.Current.Init(this, bundle);
        ZXing.Net.Mobile.Forms.Android.Platform.Init();
        ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
        global::Xamarin.Forms.Forms.Init(this, bundle);
        AnimationViewRenderer.Init();
        LoadApplication(new App(new AndroidInitializer()));
        //try
        //{
        //    LoadApplication(new App(new AndroidInitializer()));
        //}
        //catch (Exception ex)
        //{
        //    Console.WriteLine("Error===========================================>" + ex);
        //}

    }
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
    {
        Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);

    }
}

public class AndroidInitializer : IPlatformInitializer
{
    //private Context Context { get; set; }
    //public AndroidInitializer(Context context) => Context = context;
    public void RegisterTypes(IContainerRegistry containerRegistry )
    {
        //containerRegistry.RegisterInstance(Xamarin.Forms.Forms.Context);
    }
}

}

AND APP.XAML.CS IS

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Kefi
{
public partial class App : PrismApplication
{

    //to to with Login info
    private  IAdminUserService _adminUserService;
    private  IWebApiCallService _webApiCallService;
    public static INavigationService GlobalNavigationService;
    public static UserRol UserRol = UserRol.Manager;
    private ILiteDB _liteDB;
    UnityContainer unityContainer = new UnityContainer();
    //public App() : this(null) { }

    public App(IPlatformInitializer initializer) : base(initializer)
    {
        try
        {
            _liteDB = DependencyService.Get<ILiteDB>();
            DependencyService.Get<ILiteDB>().CreateDB();
            GlobalNavigationService = NavigationService;

        }
        catch (Exception ex) { string msg = ex.Message; }

iT SHOWS GLOBALNAVIGATIONSERVICE IS NULL

Answers

  • axaaxa Member ✭✭

    In short linking will remove things that are not explicitly referenced at compile... so if something is then used during runtime that was stripped out you will get problems like this.
    Basically you need to identify which assemblies are the issue (almost certainly a user assembly) and tell the linker not to link it.

    There are some more detailed answers, including one i wrote previously but cant locate now....

  • kefikefi Member ✭✭

    what to write for skip this assembely?

  • axaaxa Member ✭✭

    go into your debug or release build folder, get all the user dlls (the ones you made) without the extention , thats what you write...

    remove them one by one until you find the one(s) that give you a problem... the idea is to skip only those that give you a problem...

  • kefikefi Member ✭✭

    I am new in xamarin . So can u give me one example of name of such file which I have to write.

  • axaaxa Member ✭✭
    edited March 20

    Ok. step by step.

    First Open your debug or release folder, find all files that end with dll that match the name of your projects AND the name of any third party libraries or NuGet that you included in your solution.

    For example I use Json.Net in my project so the assembly is named Newtonsoft.Json.dll

    Then in your main project properties go to Android Options and set the Linking as such:

    And I know for a fact that this library uses alot of Reflection so the linking process removes things that are need during run time that it cannot know about during complie.

    But eventually you will want to identify all the files in your project that might be affected like this.
    You dont need to, and can only link Sdk assemblies, but that can leave your program size larger than it needs to be.

Sign In or Register to comment.