-
Notifications
You must be signed in to change notification settings - Fork 845
Add MAUI example app to csharp samples #4078
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
base: master
Are you sure you want to change the base?
Conversation
I am stuck with these error when trying to build the app:
|
Hello |
Hi again |
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 |
I'm using a Mac since it's not possible to build the iOS sample app on Windows. |
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. |
I also tried this on Mac and encountered the same problem as Riza. I downloaded the latest VS Code and followed the instruction here: 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. |
@sauwming, for sure, i'll work on that today |
Thanks, it would be better if the sample apps can work on real devices, instead of simulators. If I tried following |
The steps for real devices are similar, but I'll improve the readme this week |
@sauwming I figure it out. The project has a conditional compilation in order to split platforme codes and resources |
Hi fowks |
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: But even after I fixed it, it still failed with "undefined references" errors. |
that's is wird... the arch on condition is for simulators running on M1/M2 macs |
I finally managed to make it work. I have to specify the
The result is an |
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:
Logcat:
|
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 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. |
Hi folks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it on Android and it no longer crashes during startup.
Need more detailed instruction though on how to run the project on real mobile devices, so you need to modify README.md
.
- Visual Studio Code & .NET MAUI - [Install steps](https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation?view=net-maui-11.0&tabs=visual-studio-code) | ||
- Java 17 | ||
- Android NDK r21d | ||
- pjsip v2.14.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to:
- Android NDKr21d or later
- pjsip v2.14.1 or later
Here I'm using NDK r28 and 2.15.1, and it seems ok
|
||
```bash | ||
|
||
TARGET_ABI=x86_64 ./configure-android |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need instruction for device too, i.e.:
For device:
./configure-android
For simulator:
TARGET_ABI=x86_64 ./configure-android
sdkmanager --install "ndk;28.0.12674087" --channel=3 --sdk_root=$ANDROID_SDK_ROOT | ||
sdkmanager --install "cmake;3.31.0" --sdk_root=$ANDROID_SDK_ROOT | ||
sdkmanager --install "build-tools;35.0.0" "platform-tools" "platforms;android-35" --sdk_root=$ANDROID_SDK_ROOT | ||
echo yes | sdkmanager --licenses --sdk_root=$ANDROID_SDK_ROOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add note:
If you are sharing the Android SDK location with Android Studio, the recommended way to install/update the SDK and accept licenses is by using Android Studio.
|
||
``` | ||
|
||
then start the android emulator, go to ``` pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui ``` and run: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs instruction for device.
Here's what I did:
For Android device:
- Open Android Studio and connect an Android device, such as by using "Pair Devices Using Wifi"
- (Optional) Start Logcat in VS Code, for obtaining Android log.
- Install Logcat: View-Extensions. Install Logcat extension.
- Start Logcat: View-Command Pallette.
- SETUP: | ||
- Visual Studio Code & .NET MAUI - [Install steps](https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation?view=net-maui-11.0&tabs=visual-studio-code) | ||
- Xcode 16.1 | ||
- pjsip v2.14.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above. add "or later"
|
||
#define PJ_CONFIG_IPHONE 1 | ||
|
||
// disable background VoIP socket, use PushKit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two defines below should not be needed.
The setting to disable background voip is: PJ_ACTIVESOCK_TCP_IPHONE_OS_BG
, which is by default 0.
No need to define min iOS version as well.
|
||
```bash | ||
|
||
export DEVPATH="`xcrun -sdk iphonesimulator --show-sdk-platform-path`/Developer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this below
|
||
```bash | ||
|
||
MIN_IOS="-miphoneos-version-min=12.2" ARCH="-arch x86_64" CFLAGS="-O2 -m32 -mios-simulator-version-min=12.2 -fembed-bitcode" LDFLAGS="-O2 -m32 -mios-simulator-version-min=12.2 -fembed-bitcode" ./configure-iphone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need instruction for device as well.
For device:
./configure-iphone
For simulator:
export DEVPATH="
xcrun -sdk iphonesimulator --show-sdk-platform-path/Developer"
...
|
||
dotnet workload restore | ||
dotnet restore | ||
dotnet build -t:Run -c Debug -f net9.0-ios -p:_DeviceName=:v2:udid=UDID_OF_YOUR_EMULATOR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need instruction for device as well.
With a real device, the code signing is more complicated using VSCode, so here's what I did:
- dotnet publish -c Debug -f net9.0-ios -p:RuntimeIdentifier=ios-arm64
- Open the resulting
.ipa
file in Xcode:pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/bin/Debug/net9.0-ios/ios-arm64/publish/pjsua2maui.ipa
Drag it to your connected device under "Devices and Simulators."
Xcode will handle the signing and deployment.
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