C
C#2y 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
TraceOP2y 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
TraceOP2y ago
Trace
TraceOP2y 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
Klarth2y 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
Accord2y 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