asusralis
Topic Author
Posts: 142
Joined: 30 Jul 2018, 05:03

[Unity] Problem building to Android on 2.2

22 May 2019, 18:25

On 2.1, if I were to load an XAML from code, I had to put it in the "Preloaded" xamls in the Noesis settings. When I omitted this step, the xaml would not load on Android. On 2.2, I can't seem to find the preloaded list (which is great, because having to register each xaml asset file was terrible).

However, when I build to Android, the log says it cannot find my xaml asset files.

[noesis] Xaml not found 'Assets/Project/Source/Views/Resources/Pages/ExpeditionPageView.xaml'

It's certainly there, because it works without error when not on Android. What exactly am I doing wrong?
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: [Unity] Problem building to Android on 2.2

23 May 2019, 15:19

Since 2.2 version runtime dependencies should be specified in the corresponding XAML by using the extension property Xaml.Dependencies:
<UserControl x:Class="Localization.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions">

  <noesis:Xaml.Dependencies>
    <noesis:Dependency Source="Language-en.xaml"/>
    <noesis:Dependency Source="Language-fr.xaml"/>
    <noesis:Dependency Source="Language-jp.xaml"/>
  </noesis:Xaml.Dependencies>
  ...
</UserControl>
This creates a dependency that you can view when inspecting the xaml asset.
 
asusralis
Topic Author
Posts: 142
Joined: 30 Jul 2018, 05:03

Re: [Unity] Problem building to Android on 2.2

23 May 2019, 17:54

Does this have to be put in every xaml that references another? Or can I put all of them in my resource XAML?

Why exactly do you need to do this for every xaml? It seems odd I can't just load any xaml from resources and use it without registering it.
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Problem building to Android on 2.2

25 May 2019, 10:20

I think, the explanation give by sfernandez was not very clear. A runtime dependency is a XAML that's not referenced in any other way. So, if you have a XAML for usercontrol and that usercontrol is being used in another XAML and that XAML is attached to a NoesisView. Then you don't need to do anything. It will work automatically. You can see the automatic dependencies calculated for each XAML in the inspector properties.

Only in the rare case you need to load a XAML that is not referenced elsewhere you need to inject a manual dependency. Please have a look at our Localization sample to see how to inject manual dependencies using the property Xaml.Dependencies.
 
asusralis
Topic Author
Posts: 142
Joined: 30 Jul 2018, 05:03

Re: [Unity] Problem building to Android on 2.2

25 May 2019, 15:44

That makes more sense, but I'm still confused.

I have a navigation service that, when requested to load a 'page', which is just a UserControl in an xaml file, loads an xaml like this:
control = (UserControl)Noesis.GUI.LoadXaml("PAGE.xaml");

Root.RegisterName(xamlName, control);

Root.Children.Add(control);
I then add this to my root xaml. On 2.1, this only worked if I registered the xamls in the 'preloaded' list in the Noesis settings. It would still work in Unity, but when I built it to Android, it couldn't find the xaml files.

In 2.2, this 'preloaded' list doesn't exist anymore. So far, I have two problems:

1): Every time I open Unity up and try to play it, I get "Xaml not found." Once I click the 'reimport all xaml' button, this error is fixed, but nothing seems to change according to my source control. So I'm not sure how to actually fix this error.

2): Once I do reimport all xaml assets, it works fine in Unity, but when I build to Android and try to open a page, it says it cannot find any xaml files.

Hopefully you understand my confusion, because from what I can tell the situation you said, "it should work automatically" should apply to what I'm doing? If the xaml is in a Resources folder, and the path is correct, isn't all I should have to do is load the xaml using Noesis.GUI.LoadXaml?

Thank you for the help!
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Problem building to Android on 2.2

25 May 2019, 16:55

If "PAGE.xaml" is not referenced by any other XAML then you need to that manually. You can use the Xaml.Dependencies, for example in the main window XAML of your project (as we are doing in the Localization sample).

Or you can do the same as we were doing in 2.1 with the preloaded list, put a collection in one of your scripts and attach the XAML there. That way Unity will know that the asset must be packaged. Using the folder Resources is not recommended because everything put there will be packaged, being used or not.
 
asusralis
Topic Author
Posts: 142
Joined: 30 Jul 2018, 05:03

Re: [Unity] Problem building to Android on 2.2

25 May 2019, 22:53

Why exactly does this need to be done, though? I have a lot of different xamls - around 20 and growing. If I forget to add one, none of my builds won't work? That just seems like such a problem to keep continually checking and updating.

Is it because, like you mention at the end of your reply, they're not being added to the build because they're not referenced? If they're all in Resources, why wouldn't they work without having to reference them then?

I don't really mind if they're all added to the build... Xaml files are extremely small, and I'm using all that are in my project. Is that the reason why this problem exists?

Thank you for your help.
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Problem building to Android on 2.2

25 May 2019, 23:52

If you have the XAMLs in a /Resources/ folder then you can do the following (not recommended because it is not compatible with Blend/WPF):
NoesisXaml xaml = Resources.Load<NoesisXaml>("Main/Menu01.xaml");
Grid root = (Grid)xaml.Load();
If you inspect the code of NoesisXaml.Load() you will see it is doing a Noesis.GUI.LoadXaml() internally.

Who is online

Users browsing this forum: Ahrefs [Bot] and 40 guests