fsprojects / Avalonia.FuncUI

Develop cross-plattform GUI Applications using F# and Avalonia!
https://funcui.avaloniaui.net/
MIT License
889 stars 72 forks source link

AvaloniaSplashActivity not available #417

Closed Ecsodikas closed 2 months ago

Ecsodikas commented 2 months ago

Hi everyone,

I was playing around with FuncUI and I am really happy with it. The problem I encountered was when I tried to deploy my app for Android. I pretty much copy & pasted the templates and my problem is in this file SplashActivity.fs. For some reason there is no AvaloniaSplashActivity.

error FS0039: The type 'AvaloniaSplashActivity' is not defined. Maybe you want one of the following:   AvaloniaMainActivity [/home/ecsodikas/Repositories/Nachruf/Nachruf.Android/Nachruf.Android.fsproj]

It runs flawlessly on the desktop build.

The complete file looks like this:

namespace Nachruf.Android

open Android.App
open Android.Content
open Android.Net
open Avalonia.Android
open Avalonia.Android;

type Application = Android.App.Application

[<Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)>]
type SplashActivity() =
    inherit AvaloniaSplashActivity<Nachruf.App>()

    override this.CustomizeAppBuilder builder =
        Nachruf.About.urlOpen <-
            fun url ->
                this.StartActivity(
                    (new Intent(Intent.ActionView, Uri.Parse url))
                        .SetFlags(ActivityFlags.ClearTop ||| ActivityFlags.NewTask)
                )

        base.CustomizeAppBuilder builder

    override this.OnResume() =
        base.OnResume()
        this.StartActivity(new Intent(Application.Context, typeof<MainActivity>))

and the fsproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <Nullable>enable</Nullable>
    <ApplicationId>eu.ecsodikas.Nachruf</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <AndroidSdkDirectory>/home/ecsodikas/.android/sdk</AndroidSdkDirectory>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)'=='Release'">
      <PublishTrimmed>True</PublishTrimmed>
      <RunAOTCompilation>True</RunAOTCompilation>
      <AndroidEnableProfiledAot>True</AndroidEnableProfiledAot>
      <!-- https://github.com/dotnet/runtime/issues/79910 -->
      <EnableLLVM>False</EnableLLVM>
      <AndroidLinkTool>r8</AndroidLinkTool>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.3.1.3" />
      <PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel" Version="2.3.1.3" />
      <PackageReference Include="Avalonia.Android" Version="$(AvaloniaVersion)" />
      <ProjectReference Include="..\Nachruf\Nachruf.fsproj" />

      <None Include="Properties\AndroidManifest.xml" />
      <AndroidResource Include="Icon.png">
        <Link>Resources\drawable\Icon.png</Link>
      </AndroidResource>
      <AndroidResource Include="Resources\**\*" />
      <Compile Include="MainActivity.fs" />
      <Compile Include="SplashActivity.fs" />
    </ItemGroup>

</Project>

Is there some documentation where the AvaloniaSplashActivity has gone or what replaced it? Thanks in advance!

Numpsy commented 2 months ago

I haven't tried it myself, but it looks like AvaloniaSplashActivity was folded into AvaloniaMainActivity in https://github.com/AvaloniaUI/Avalonia/pull/11854

The current Avalonia Android template looks to be using MainActivity directly - https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/c9fa33d8dcc5d551c0a4aff7279701b0e614be10/templates/fsharp/xplat/AvaloniaTest.Android/Activities.fs#L16

JaggerJo commented 2 months ago

I'm closing this - reach out if this is still an issue.