C
C#14mo ago
Trace

❔ avalonia cross platform issue

Im trying to port my avalonia project to android, but it just shows a white screen, android code is based on the hello world sample and the project structure was re-shaped around the "Main, Main.Desktop, Main.Android" style of project management
5 Replies
Trace
Trace14mo ago
csproj.android:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-android</TargetFramework>
<SupportedOSPlatformVersion>26</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ApplicationId>com.TraceEntertains.installer</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<AndroidPackageFormat>apk</AndroidPackageFormat>
<AndroidEnableProfiledAot>False</AndroidEnableProfiledAot>
</PropertyGroup>

<ItemGroup>
<AndroidResource Include="..\installer\Assets\window_icon.png">
<Link>Resources\drawable\Icon.png</Link>
</AndroidResource>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Android" Version="11.0.0-preview8" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0-preview8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\installer\installer.csproj" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-android</TargetFramework>
<SupportedOSPlatformVersion>26</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ApplicationId>com.TraceEntertains.installer</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<AndroidPackageFormat>apk</AndroidPackageFormat>
<AndroidEnableProfiledAot>False</AndroidEnableProfiledAot>
</PropertyGroup>

<ItemGroup>
<AndroidResource Include="..\installer\Assets\window_icon.png">
<Link>Resources\drawable\Icon.png</Link>
</AndroidResource>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Android" Version="11.0.0-preview8" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0-preview8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\installer\installer.csproj" />
</ItemGroup>
</Project>
main csproj
Trace
Trace14mo ago
Trace
Trace14mo ago
app.axaml
<Application
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CTGP7InstallerSharp.App">
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
<Application
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CTGP7InstallerSharp.App">
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
app.axaml.cs
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace installer
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
base.OnFrameworkInitializationCompleted();
}
}
}
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace installer
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
base.OnFrameworkInitializationCompleted();
}
}
}
Klarth
Klarth14mo ago
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
Android isn't a desktop app. It's an ISingleViewApplicationLifetime at best...you still don't control the window, AFAIK, but I haven't used Avalonia with mobile. I would check the samples in their repo or maybe dig into how Wieslaw has his stuff setup. eg. https://github.com/wieslawsoltes/ChatGPT/blob/main/src/ChatGPT.UI.Android/SplashActivity.cs
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Why deconstuctor/Finalize example not working in vs 2022. Anything missing``` using System; class GCcollection { public GCcollection() { Console.WriteLine("H❔ Blazor Project won't compile - Previously did without any changes.Hi, I have a blazor project, which previously compiled and ran without issue. My last commit was sub❔ How can I import json file inside a sass file?I have looked around in the web for various solutions and found it could be done easily in javascrip❔ .NET Core 7.0 SDK shown as installed by "apt-get" but not used by "dotnet" commandI am using dotnet-cli and I have been facing this issue with my dotnet installation on Ubuntu Jammy ❔ EF Core Fluent API - Unidirectional one to many relationshipHow can I implement a one to many unidirectional relationship using EF Core fluent API? (Image 1) I❔ Is it a problem to be creating lots of empty lists etc just to avoid null checks?Over thousands of items, is this expensive or a problem? What is a better way to avoid null checks? ❔ Decent terminal UI library or solutionI'm writing a terminal-based application that requires a TUI. I've tried Terminal.Gui but I've found❔ Unable to bind CollectionView to DictionaryWhen binding a `CollectionView` to a Dictionary, MAUI throws a XAML exception of ``` Error: Cannot ✅ How to make program wait before executing next print line?```cs Console.WriteLine("This is line one"); // sleep 2 seconds Console.WriteLine("This is line two"✅ Navigating my window only display the next page's name instead of its contentsI hope you're all well. I got stuck on a WPF XAML problem where my pages wouldn't navigate and after