Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MAUI example app to csharp samples #4078

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

weslleymurdock
Copy link

This covers #4077
I've created the sample application for both iOS & Android platforms, and some modifications on makefile to generate c# PINVOKE classes to the right project as well

@CLAassistant
Copy link

CLAassistant commented Sep 15, 2024

CLA assistant check
All committers have signed the CLA.

@trengginas
Copy link
Member

I am stuck with these error when trying to build the app:

/usr/local/share/dotnet/sdk/8.0.403/Microsoft.Common.CurrentVersion.targets(2303,5): error MSB4803: The task "ResolveNativeReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details. [/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/pjsua2maui.csproj::TargetFramework=net8.0-android]
/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/Platforms/iOS/CallPageHandler.cs(4,40): error CS0234: The type or namespace name 'Compatibility' does not exist in the namespace 'Microsoft.Maui.Controls.Handlers' (are you missing an assembly reference?) [/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/pjsua2maui.csproj::TargetFramework=net8.0-ios]
/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/Platforms/iOS/AppDelegate.cs(6,28): error CS0246: The type or namespace name 'MauiUIApplicationDelegate' could not be found (are you missing a using directive or an assembly reference?) [/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/pjsua2maui.csproj::TargetFramework=net8.0-ios]
/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/Platforms/iOS/CallPageHandler.cs(16,33): error CS0246: The type or namespace name 'VisualElementRenderer<>' could not be found (are you missing a using directive or an assembly reference?) [/pjsip/test/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/pjsua2maui.csproj::TargetFramework=net8.0-ios]

@weslleymurdock
Copy link
Author

Hello
Which version of dotnet you`re using
Please post the dotnet setup details

@weslleymurdock
Copy link
Author

Hi again
I'll try to create a global.json to configure the .ned sdk version as the same i've used

@weslleymurdock
Copy link
Author

Hello @trengginas I've reproduced this when i'm used the global on a mac. And i've done the android sample on windows, which uses the ResolveNativeReference MSBuild Task for resolve the android libs. Try use windows while i'm working on a new android sample

@trengginas
Copy link
Member

I'm using a Mac since it's not possible to build the iOS sample app on Windows.

@weslleymurdock
Copy link
Author

To "build on windows" you can use the ssh connection of visual studio to debug and run the iOS app on emulator inside Windows Environment.
But if is not possible use a windows pc, try to build one target only (e.g Android only or iOS only).

@sauwming
Copy link
Member

I also tried this on Mac and encountered the same problem as Riza.

I downloaded the latest VS Code and followed the instruction here:
https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation?view=net-maui-9.0&tabs=visual-studio-code

Would you be able to make this work on Mac? Also, please provide us step by step detail (sorry, we are not familiar at all with MAUI project), something similar to #3584.

@weslleymurdock
Copy link
Author

@sauwming, for sure, i'll work on that today

@sauwming
Copy link
Member

Thanks, it would be better if the sample apps can work on real devices, instead of simulators. If I tried following Readme.md, I would encounter the following error:
building for iOS Simulator, but linking in object file built for iOS

@weslleymurdock
Copy link
Author

The steps for real devices are similar, but I'll improve the readme this week

@weslleymurdock
Copy link
Author

@sauwming I figure it out. The project has a conditional compilation in order to split platforme codes and resources
And the inclusion of arm64 library is included in x86_64, causing the bad linking
I'll updathe the pr with a including conditional check on arm64 lib

@weslleymurdock weslleymurdock marked this pull request as draft December 4, 2024 04:10
@weslleymurdock
Copy link
Author

Hi fowks
Im working on desktop maui samples, so i maked this as draft
It works on windows, but it still need the native platform controls implementation for video win

@sauwming
Copy link
Member

sauwming commented Dec 4, 2024

I still haven't managed to make it work on a real device.

On iOS, it will fail due to an extra opening parenthesis here:
<ItemGroup Condition="(($(RuntimeIdentifier.StartsWith('iossimulator-arm64')))">

But even after I fixed it, it still failed with "undefined references" errors.

@weslleymurdock
Copy link
Author

that's is wird... the arch on condition is for simulators running on M1/M2 macs
the undefined references is about linking
could you please post me a build with diag in order to see whats going on with linking?

@sauwming
Copy link
Member

sauwming commented Dec 5, 2024

I finally managed to make it work. I have to specify the RuntimeIdentifier, otherwise it will link with simulator.

dotnet publish -c Debug -f net9.0-ios -p:RuntimeIdentifier=ios-arm64

The result is an .ipa (iOS app package) in pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/bin/Debug/net9.0-ios/ios-arm64/publish/pjsua2maui.ipa, which I can then deploy to the device using Xcode. Not sure if there is an easier way to do this.

@sauwming
Copy link
Member

sauwming commented Dec 5, 2024

The app can run on iOS device. On Android, however, it crashes immediately, as soon as it displays the blue ".NET" logo.

There doesn't seem to be any wrong indications during the build process nor in the Logcat:

dotnet build -t:Run -c Debug -f net9.0-android -v:diag
/usr/local/share/dotnet/sdk/9.0.100/MSBuild.dll -nologo -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/local/share/dotnet/sdk/9.0.100/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/local/share/dotnet/sdk/9.0.100/dotnet.dll -maxcpucount -property:Configuration=Debug -target:Restore -tlp:default=auto -tlp:verbosity=quiet -verbosity:m -verbosity:diag ./pjsua2maui.sln
/usr/local/share/dotnet/sdk/9.0.100/MSBuild.dll -nologo -consoleloggerparameters:Summary -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/local/share/dotnet/sdk/9.0.100/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/local/share/dotnet/sdk/9.0.100/dotnet.dll -maxcpucount -property:TargetFramework=net9.0-android -property:Configuration=Debug -t:Run -tlp:default=auto -verbosity:m -verbosity:diag ./pjsua2maui.sln
  pjsua2maui net9.0-android succeeded with 4 warning(s) (87.8s) → pjsua2maui/bin/Debug/net9.0-android/pjsua2maui.dll
    /pjproject-maui-android/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/obj/Debug/net9.0-android/generated/src/Org.Pjsip.PjCamera.cs(20,60): warning CS0618: 'Camera' is obsolete: 'This class is obsoleted in this android platform'

[3 more warnings similar as above]

Build succeeded with 4 warning(s) in 88.2s

Logcat:

12-05 14:06:02.687  1648 17182 W ActivityManager: crash : com.teluu.pjsua2maui,10302
12-05 14:06:02.687  1648  7105 W ActivityTaskManager:   Force finishing activity com.teluu.pjsua2maui/crc649fb2e8f84f92675e.MainActivity

@weslleymurdock
Copy link
Author

When i wrote the sample, i used the .NET 8.0 and it runs fine on android. However, i've upgraded to .NET 9.0 and didn't tested it.

I've debuging the android app on VS using windows, and it shows the crash when the app set's the camera manager by invoking the Java code injected on the app., but it seems that the java code does not being injected to app when putting the files on project app and flagging it as <AndroidJavaSource>SomeFile.java</AndroidJavaSource> .

I'm currently writing a softphone for a company, and faced this issue. My workaround was create a Class Library Project, and produce a library. This way the file is injected to final binary, and the app can handle the PjCamera2 methods loading for set the CameraManager.

I don't know if there is a issue with .NET 9.0, but i can provide a new solution, where the app consumes the wrapper classes and native libraries from a .net maui library project, or even a local nuget package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants