Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

[Android] Sample project from this repo is very laggy

Open Alex-Dobrynin opened this issue 2 years ago • 12 comments

I downloaded this repo and built sample project for android and ran it. If say that it lags when scrolling or drawing is to say nothing. Every ui interaction is accompanied with big delay about few secs.

OnePlus 9 Pro Android 12

Alex-Dobrynin avatar Feb 23 '22 02:02 Alex-Dobrynin

Did you build it in release mode with AOT enabled? It isn't fast. But definitely way faster than "big delay about few secs" on my OnePlus 7T Pro Android 11.

Also did you used net6-android (new sdk) or monodroid (old sdk) target? It shouldn't matter too much on performance, but just to know.

maxkatz6 avatar Feb 23 '22 03:02 maxkatz6

I didnt change any settings of android demo project ControlCatalog.Android

Alex-Dobrynin avatar Feb 28 '22 14:02 Alex-Dobrynin

Well, then try to build it in release mode, AOT will be enabled automatically (only in ControlCatalog.Android). You need these lines enabled https://github.com/AvaloniaUI/Avalonia/blob/master/samples/ControlCatalog.Android/ControlCatalog.Android.csproj#L23-L25

Note that NDK might fail if you SDK is installed in program files directory. It can't work if there are spaces in the path. So you would need to reinsall/move/symlink android SDK to another directory and change it in xamarin settings.

maxkatz6 avatar Feb 28 '22 16:02 maxkatz6

Its not so easy to do, because when downloading project from github and trying to build it fails. tons of errors. I need to fix dependencies manually. and after last try, i deleted the project from pc

Alex-Dobrynin avatar Mar 01 '22 11:03 Alex-Dobrynin

Well, sadly that's xamarin experience on .net. It's promised to be better with net6, but not yet. Avalonia team can't really make it better.

maxkatz6 avatar Mar 01 '22 11:03 maxkatz6

@maxkatz6 sorry, but you are not definitelly correct

All text below is not about to say smb is good or bad... it is the problem - if developer can't build solution "out of the box" developer would not use the solution... would @Alex-Dobrynin try to use Avalonia in commercial project? We do not know... How many other developers failed even to build master and said "yap... nooo... avalonia is too risky, i can't even build master, how can i trust my commercial solution to that guys"? Once again we do not know... may be therte are 10 of them, may be 10k.

Firstly if you do recommend to use <RunAOTCompilation>True</RunAOTCompilation> it should be set by default in ControlCatalog.Android.csproj for Release build (for now it is false in master)

I'v just checked out two repos https://github.com/AvaloniaUI/Wordle-onia and main Avalonia repo

I can build, run & deploy Wordle-onia but not main repo.

I'v tried to buid it from VS2022... and i do see some strange errors (OK, I do see that it is some crazy story about VS2022 + msbuild and may, be Xamarin.Legacy.Sdk)

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1805,5): error : Project '../../src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj' targets 'net6.0-android'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v6.0'.

Let's go to command line and use dotnet build .\Avalonia.sln -c Release:

output (sorry for Russian):

D:\job\Avalonia\src\Android\Avalonia.AndroidTestApplication\MainActivity.cs(21,37): error CS0305: Использование универсального тип "AvaloniaActivity<TApp>" требует аргументы типа 1. [D:\job\Avalonia\src\Android\Avalonia.AndroidTestApplication\Avalonia.AndroidTestApplication.csproj]
D:\job\Avalonia\src\Android\Avalonia.AndroidTestApplication\MainActivity.cs(23,33): error CS0115: "MainBaseActivity.OnCreate(Bundle)": не найден метод, пригодный для переопределения. [D:\job\Avalonia\src\Android\Avalonia.AndroidTestApplication\Avalonia.AndroidTestApplication.csproj]

hmm, we do see 2 CSC errors: 305 and 115... this is compiler errors... sorry but making Avalonia compilable is the thing Avalonia Team can do :)

Ok, let's go back to VS and make some fixies.

Trying to build will fail again because... again strange issues in msbuild output, close solution, go to cmd, build - success... ok, looks like smth is with msbuild and VS... sorry, my time is off to make investigations :(((

I do know that there are some problems with net6 and previous net versions, yes... but any way master should be compileable & there should be some way & instructions how one can build Avalonia (i want to believe Avalonia Teammates can build Avalonia.sln :)))

PS it would be cool to publish ControlCatalog to Android/iOS markets :))))

ili avatar Mar 15 '22 14:03 ili

<RunAOTCompilation>True</RunAOTCompilation> is the SDKs default in release mode

Gillibald avatar Mar 15 '22 14:03 Gillibald

Firstly if you do recommend to use <RunAOTCompilation>True</RunAOTCompilation> it should be set by default in ControlCatalog.Android.csproj for Release build

Oh, you are right. It was enabled before, but was disabled with another PR. Good catch.

PS it would be cool to publish ControlCatalog to Android/iOS markets :))))

Yeah, we want something like this. "Wordle-onia" will go first to the apple store. ControlCatalog is definitely can't be in the public markets, because it's more suitable for developers to test many controls. Not really representable. Instead, some nice application with control samples should be. @danwalmsley and @jmacato were working on this.

I'v tried to buid it from VS2022... and i do see some strange errors

Building in VS sometimes is pita. Majority of the dev team are using Rider and never saw most of VS-specific errors. I saw this one what you mentioned before doing android/ios projects, but can't reproduce it anymore.

Let's go to command line and use dotnet build .\Avalonia.sln -c Release:

Yes, this one is definitely broken. After these two recent PRs: https://github.com/AvaloniaUI/Avalonia/pull/7756 https://github.com/AvaloniaUI/Avalonia/pull/7781 ControlCatalog.Android was updated to work with new API, but that test project wasn't. I will make a PR to fix it.

maxkatz6 avatar Mar 15 '22 15:03 maxkatz6

@maxkatz6 cool :-):-) Will wait for fix & demo app (Wordle-onia is not looking to be representable from my side small controls number, and previosly i'v faced with perfomance problems on low-end device)

Anyway, please, make the solution buildable :-)

ili avatar Mar 15 '22 16:03 ili

IIRC the GPU backend (OpenGL ES) of Avalonia for Android hasn't been enabled? Then I think it's expected to see rendering laggy on Android.

hez2010 avatar Mar 17 '22 04:03 hez2010

@hez2010 It is enabled by default.

maxkatz6 avatar Mar 17 '22 21:03 maxkatz6

Note that NDK might fail if you SDK is installed in program files directory. It can't work if there are spaces in the path. So you would need to reinsall/move/symlink android SDK to another directory and change it in xamarin settings.

After moving to another directory how do I change xamarin settings? I am building the application using dotnet build -c Release and I am getting No Android NDK found issues on window.

EDIT: I did not install Xamarin on Visual Studio. Now its working fine, installed NDK through the xamarin android tools within VS

geocine avatar Jul 22 '22 17:07 geocine