From 544ee5d06a8696f7eb7af061ac56fa712d69fccf Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 22 Oct 2024 13:30:25 -0400 Subject: [PATCH 01/12] [maui] Update Native Library Interop docs for net9.0 Updates the Maui.NativeLibraryInterop docs to mention the new build items available in the .NET for Android, iOS, Mac Catalyst, macOS, and tvOS SDKs. --- docs/maui/native-library-interop/index.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/maui/native-library-interop/index.md b/docs/maui/native-library-interop/index.md index f95397a31..5740535b7 100644 --- a/docs/maui/native-library-interop/index.md +++ b/docs/maui/native-library-interop/index.md @@ -49,33 +49,31 @@ The binding build process is extended to obtain and build native SDK dependencie ``` -Android binding projects will add a `@(NLIGradleProjectReference)` item that points to the root folder that contains the native wrapper gradle project: +Android binding projects will add a `@(AndroidGradleProject)` item that points to a build.gradle file that will be used to build the gradle project: ```xml - + newbinding - + ``` -iOS binding projects will add an `@(NLIXcodeProjectReference)` item that points to the native wrapper Xcode project: +iOS binding projects will add an `@(XcodeProject)` item that points to the native wrapper Xcode project: ```xml - + NewBinding - NewBinding - true - + ``` @@ -83,7 +81,7 @@ Android binding projects generate the API definition automatically taking into a ![Conceptual overview: NativeLibraryInterop for Android](../images/native-library-interop/nativelibraryinterop-conceptual-overview-android.png "Conceptual overview of NativeLibraryInterop for Android") -An iOS binding library project must include an explicitly defined API. To help with this, [Objective-Sharpie](/xamarin/cross-platform/macios/binding/objective-sharpie/#overview) can be run automatically on the resulting native framework to produce an [API definition file](/xamarin/cross-platform/macios/binding/objective-c-libraries?tabs=macos#The_API_definition_file) (ApiDefinition.cs) alongside it. This can serve as a helpful reference when creating and maintaining the ApiDefintion.cs file used by the iOS binding project. +An iOS binding library project must include an explicitly defined API. To help with this, [Objective-Sharpie](/xamarin/cross-platform/macios/binding/objective-sharpie/#overview) can be manually run on the resulting native framework to produce an [API definition file](/xamarin/cross-platform/macios/binding/objective-c-libraries?tabs=macos#The_API_definition_file) (ApiDefinition.cs) alongside it. This can serve as a helpful reference when creating and maintaining the ApiDefintion.cs file used by the iOS binding project. ![Conceptual overview: NativeLibraryInterop for iOS](../images/native-library-interop/nativelibraryinterop-conceptual-overview-ios.png "Conceptual overview of NativeLibraryInterop for iOS") From b49af9dc090d41da0c4e4fcafa04a07b0a216501 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Wed, 23 Oct 2024 13:30:30 -0400 Subject: [PATCH 02/12] Update native library interop get-started --- .../native-library-interop/get-started.md | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index b42d17172..c9b57411d 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -19,7 +19,7 @@ Install prerequisites: - [.NET MAUI workload](https://github.com/dotnet/core/blob/main/release-notes/6.0/install-maui.md#cli-installation) (via Visual Studio or CLI ```dotnet workload install maui```) - [Android SDK](https://developer.android.com/tools) - [Android Studio](https://developer.android.com/studio) -- [Objective-Sharpie](https://aka.ms/objective-sharpie) (required for the C# APIs to be auto-generated) +- [Objective-Sharpie](https://aka.ms/objective-sharpie) (used to generate the C# API surface) - [Xamarin.iOS](https://download.visualstudio.microsoft.com/download/pr/ceb0ea3f-4db8-46b4-8dc3-8049d27c0107/3960868aa9b1946a6c77668c3f3334ee/xamarin.ios-16.4.0.23.pkg) (required for Objective-Sharpie to work) - [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [Visual Studio Code](https://code.visualstudio.com/download) - [Xcode](https://developer.apple.com/xcode/) @@ -92,8 +92,18 @@ On the native side, make updates in _template/macios/native/NewBinding/NewBindin Back on the .NET side, we are now ready to interop with the native library: -1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ to test everything is plugged in correctly and good to go. If successful, you should see the generated C# bindings at _template/macios/native/NewBinding/bin/Release/net8.0-ios/sharpie/NewBinding/ApiDefinitions.cs_. -1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _template/macios/native/NewBinding/bin/Release/net8.0-ios/sharpie/NewBinding/ApiDefinitions.cs_. +1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ to test everything is plugged in correctly and good to go. +1. Run `sharpie` against the header files in the xcframework created by the binding project: + ``` + sharpie bind + --output=sharpie-out + --namespace=NewBindingMaciOS + --sdk=iphoneos18.0 + --scope=_template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/Headers + _template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/Headers/NewBinding-Swift.h + + ``` +1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _sharpie-out/ApiDefinitions.cs_. 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. #### API Definition: Android @@ -106,17 +116,16 @@ On the native side, make updates in _template/android/native/app/src/main/java/c Back on the .NET side, we are now ready to interop with the native library: 1. Run `dotnet build` from _template/android/NewBinding.Android.Binding_ to test everything is plugged in correctly and good to go. (Note: This step will require that you have JDK 17 installed) -1. Reference any Android binding dependencies by adding the following code to _template/sample/MauiSample.csproj_ for each dependency. Replace _{yourDependencyLibrary.aar}_ with the required .aar file for the dependency you are binding. (Note: The gradle/maven dependencies often need to be explicitly referenced, as they are not automatically bundled into your library. The _build.gradle.kts_ file is configured to copy dependencies into a bin/outputs/deps folder for you to reference in your application) +1. Reference any Android binding dependencies by adding `@(AndroidMavenLibrary)` or `@(PackageReference)` elements to satisfy the java dependency chain for the native library you are binding. (Note: The gradle/maven dependencies often need to be explicitly referenced, as they are not automatically bundled into your library.) ```xml - - false - false - + ``` +For more information about this process, see https://learn.microsoft.com/en-us/dotnet/android/binding-libs/advanced-concepts/resolving-java-dependencies. + > [!NOTE] > You can rename the placeholder ```DotnetNewBinding``` class to better reflect the native library being wrapped. For more examples and tips for writing the API definitions, read more in the section below: [Modify an existing binding](#modify-an-existing-binding). @@ -202,7 +211,7 @@ public static func unregister(completion: @escaping (NSError?) -> Void) { The other half will be to update the _ApiDefinitions.cs_ file in the binding project to expose this new method. There are two ways you can go about this: 1. You can manually add the required code -2. When the binding project builds, objective sharpie is run and an _ApiDefinitions.cs_ file is generated inside of the _native/macios/bin/sharpie_ folder (this path will vary based on the project you are working on of course). You can try to find the relevant changes from this file and copy them over manually, or try copying over the whole file and looking at the diff to find the part you need. +2. After building the binding project, you can run the objective sharpie tool to generate an _ApiDefinitions.cs_ file. You can try to find the relevant changes from this file and copy them over manually, or try copying over the whole file and looking at the diff to find the part you need. In this case, the changes to _ApiDefinitions.cs_ would be: From 74ee0f0122c7095542f515a678da445cc4ffab28 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Wed, 23 Oct 2024 14:18:10 -0400 Subject: [PATCH 03/12] Update sharpie command, use relative docs url --- .../native-library-interop/get-started.md | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index c9b57411d..1778f4723 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -19,7 +19,7 @@ Install prerequisites: - [.NET MAUI workload](https://github.com/dotnet/core/blob/main/release-notes/6.0/install-maui.md#cli-installation) (via Visual Studio or CLI ```dotnet workload install maui```) - [Android SDK](https://developer.android.com/tools) - [Android Studio](https://developer.android.com/studio) -- [Objective-Sharpie](https://aka.ms/objective-sharpie) (used to generate the C# API surface) +- [Objective-Sharpie](https://aka.ms/objective-sharpie) (used to manually generate the C# APIs) - [Xamarin.iOS](https://download.visualstudio.microsoft.com/download/pr/ceb0ea3f-4db8-46b4-8dc3-8049d27c0107/3960868aa9b1946a6c77668c3f3334ee/xamarin.ios-16.4.0.23.pkg) (required for Objective-Sharpie to work) - [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [Visual Studio Code](https://code.visualstudio.com/download) - [Xcode](https://developer.apple.com/xcode/) @@ -93,18 +93,15 @@ On the native side, make updates in _template/macios/native/NewBinding/NewBindin Back on the .NET side, we are now ready to interop with the native library: 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ to test everything is plugged in correctly and good to go. -1. Run `sharpie` against the header files in the xcframework created by the binding project: - ``` - sharpie bind - --output=sharpie-out - --namespace=NewBindingMaciOS - --sdk=iphoneos18.0 - --scope=_template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/Headers - _template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/Headers/NewBinding-Swift.h - - ``` -1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _sharpie-out/ApiDefinitions.cs_. -1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. +1. Optionally use objective sharpie to generate an updated ApiDefinitions.cs file that reflects any changes in your swift code. + 1. Run `sharpie xcode -sdks` to get a list of valid target SDK values for the bind command. Select the value that aligns with the platform and version you are targeting to use with the next command, for example `iphoneos18.0`. + 1. Run `sharpie bind` against the header files in the xcframework created by the binding project: + ``` + cd _template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework && + sharpie bind --output=sharpie-out --namespace=NewBindingMaciOS --sdk=iphoneos18.0 --scope=Headers Headers/NewBinding-Swift.h + ``` + 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _sharpie-out/ApiDefinitions.cs_. + 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. #### API Definition: Android @@ -124,7 +121,7 @@ Back on the .NET side, we are now ready to interop with the native library: ``` -For more information about this process, see https://learn.microsoft.com/en-us/dotnet/android/binding-libs/advanced-concepts/resolving-java-dependencies. +For more information about this process, see the [AndroidMavenLibrary reference](dotnet/android/binding-libs/advanced-concepts/android-maven-library) documentation. > [!NOTE] > You can rename the placeholder ```DotnetNewBinding``` class to better reflect the native library being wrapped. For more examples and tips for writing the API definitions, read more in the section below: [Modify an existing binding](#modify-an-existing-binding). From 2f092a3894e84f4df069922d4758e65fea03a33e Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Wed, 23 Oct 2024 14:27:44 -0400 Subject: [PATCH 04/12] Add leading / --- docs/maui/native-library-interop/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 1778f4723..586bfa61c 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -121,7 +121,7 @@ Back on the .NET side, we are now ready to interop with the native library: ``` -For more information about this process, see the [AndroidMavenLibrary reference](dotnet/android/binding-libs/advanced-concepts/android-maven-library) documentation. +For more information about this process, see the [AndroidMavenLibrary reference](/dotnet/android/binding-libs/advanced-concepts/android-maven-library) documentation. > [!NOTE] > You can rename the placeholder ```DotnetNewBinding``` class to better reflect the native library being wrapped. For more examples and tips for writing the API definitions, read more in the section below: [Modify an existing binding](#modify-an-existing-binding). From 2ae238b8a7695a04df48d40d3d0f855a11d53710 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 14:46:42 -0800 Subject: [PATCH 05/12] Update docs/maui/native-library-interop/get-started.md Co-authored-by: Rachel Kang --- docs/maui/native-library-interop/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 586bfa61c..5dbfbe75f 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -93,7 +93,7 @@ On the native side, make updates in _template/macios/native/NewBinding/NewBindin Back on the .NET side, we are now ready to interop with the native library: 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ to test everything is plugged in correctly and good to go. -1. Optionally use objective sharpie to generate an updated ApiDefinitions.cs file that reflects any changes in your swift code. +1. Use objective sharpie to generate the C# bindings for your Swift API updates: 1. Run `sharpie xcode -sdks` to get a list of valid target SDK values for the bind command. Select the value that aligns with the platform and version you are targeting to use with the next command, for example `iphoneos18.0`. 1. Run `sharpie bind` against the header files in the xcframework created by the binding project: ``` From 26002a711b3848924a696f798e004e146f20dd8a Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 14:46:57 -0800 Subject: [PATCH 06/12] Update docs/maui/native-library-interop/get-started.md Co-authored-by: Rachel Kang --- docs/maui/native-library-interop/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 5dbfbe75f..0934719fb 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -117,7 +117,7 @@ Back on the .NET side, we are now ready to interop with the native library: ```xml - + ``` From 9bde113fff82c8f22ee91b9951a0d158bbe69c83 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 14:48:04 -0800 Subject: [PATCH 07/12] Update docs/maui/native-library-interop/get-started.md Co-authored-by: Rachel Kang --- docs/maui/native-library-interop/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 0934719fb..38b7e845f 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -100,7 +100,7 @@ Back on the .NET side, we are now ready to interop with the native library: cd _template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework && sharpie bind --output=sharpie-out --namespace=NewBindingMaciOS --sdk=iphoneos18.0 --scope=Headers Headers/NewBinding-Swift.h ``` - 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _sharpie-out/ApiDefinitions.cs_. + 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _template/macios/NewBinding.MaciOS.Binding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/sharpie-out/ApiDefinitions.cs_. 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. #### API Definition: Android From 411fcbdd4ff1f755601b328d5fe175ab1b322054 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 14:48:44 -0800 Subject: [PATCH 08/12] Update docs/maui/native-library-interop/get-started.md Co-authored-by: Rachel Kang --- docs/maui/native-library-interop/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 38b7e845f..5d5dced60 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -113,7 +113,7 @@ On the native side, make updates in _template/android/native/app/src/main/java/c Back on the .NET side, we are now ready to interop with the native library: 1. Run `dotnet build` from _template/android/NewBinding.Android.Binding_ to test everything is plugged in correctly and good to go. (Note: This step will require that you have JDK 17 installed) -1. Reference any Android binding dependencies by adding `@(AndroidMavenLibrary)` or `@(PackageReference)` elements to satisfy the java dependency chain for the native library you are binding. (Note: The gradle/maven dependencies often need to be explicitly referenced, as they are not automatically bundled into your library.) +1. Reference any Android binding dependencies by adding the following code to _template/sample/MauiSample.csproj_ for each dependency. Add `@(AndroidMavenLibrary)` or `@(PackageReference)` elements as needed to satisfy the java dependency chain for the native library you are binding. (Note: The gradle/maven dependencies often need to be explicitly referenced, as they are not automatically bundled into your library.) ```xml From 8947f7448acf7e511026f7af72967207f5526720 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 14:49:08 -0800 Subject: [PATCH 09/12] Update docs/maui/native-library-interop/index.md Co-authored-by: Rachel Kang --- docs/maui/native-library-interop/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maui/native-library-interop/index.md b/docs/maui/native-library-interop/index.md index 5740535b7..d9d88c2c2 100644 --- a/docs/maui/native-library-interop/index.md +++ b/docs/maui/native-library-interop/index.md @@ -81,7 +81,7 @@ Android binding projects generate the API definition automatically taking into a ![Conceptual overview: NativeLibraryInterop for Android](../images/native-library-interop/nativelibraryinterop-conceptual-overview-android.png "Conceptual overview of NativeLibraryInterop for Android") -An iOS binding library project must include an explicitly defined API. To help with this, [Objective-Sharpie](/xamarin/cross-platform/macios/binding/objective-sharpie/#overview) can be manually run on the resulting native framework to produce an [API definition file](/xamarin/cross-platform/macios/binding/objective-c-libraries?tabs=macos#The_API_definition_file) (ApiDefinition.cs) alongside it. This can serve as a helpful reference when creating and maintaining the ApiDefintion.cs file used by the iOS binding project. +An iOS binding library project must include an explicitly defined API. To help with this, [Objective-Sharpie](/xamarin/cross-platform/macios/binding/objective-sharpie/#overview) must be run on the resulting native framework to produce an [API definition file](/xamarin/cross-platform/macios/binding/objective-c-libraries?tabs=macos#The_API_definition_file) (ApiDefinition.cs) alongside it. This can serve as a helpful reference when creating and maintaining the ApiDefintion.cs file used by the iOS binding project. ![Conceptual overview: NativeLibraryInterop for iOS](../images/native-library-interop/nativelibraryinterop-conceptual-overview-ios.png "Conceptual overview of NativeLibraryInterop for iOS") From f4ea74fa43bb6c57f4684cf7bb6920a405953fa1 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 16:05:39 -0800 Subject: [PATCH 10/12] Address feedback --- docs/maui/native-library-interop/get-started.md | 10 ++++++---- docs/maui/native-library-interop/index.md | 8 -------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 5d5dced60..42582af65 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -94,15 +94,17 @@ Back on the .NET side, we are now ready to interop with the native library: 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ to test everything is plugged in correctly and good to go. 1. Use objective sharpie to generate the C# bindings for your Swift API updates: + 1. Navigate to _template/macios/NewBinding.MaciOS.Binding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework_ in your MaciOS binding projects output folder. 1. Run `sharpie xcode -sdks` to get a list of valid target SDK values for the bind command. Select the value that aligns with the platform and version you are targeting to use with the next command, for example `iphoneos18.0`. 1. Run `sharpie bind` against the header files in the xcframework created by the binding project: ``` - cd _template/macios/native/NewBinding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework && sharpie bind --output=sharpie-out --namespace=NewBindingMaciOS --sdk=iphoneos18.0 --scope=Headers Headers/NewBinding-Swift.h ``` 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _template/macios/NewBinding.MaciOS.Binding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/sharpie-out/ApiDefinitions.cs_. 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. +See also the [objective-sharpie](previous-versions/xamarin/cross-platform/macios/binding/objective-sharpie/tools) documentation to learn more about this tool. + #### API Definition: Android On the native side, make updates in _template/android/native/app/src/main/java/com/example/newbinding/DotnetNewBinding.java_: @@ -113,15 +115,15 @@ On the native side, make updates in _template/android/native/app/src/main/java/c Back on the .NET side, we are now ready to interop with the native library: 1. Run `dotnet build` from _template/android/NewBinding.Android.Binding_ to test everything is plugged in correctly and good to go. (Note: This step will require that you have JDK 17 installed) -1. Reference any Android binding dependencies by adding the following code to _template/sample/MauiSample.csproj_ for each dependency. Add `@(AndroidMavenLibrary)` or `@(PackageReference)` elements as needed to satisfy the java dependency chain for the native library you are binding. (Note: The gradle/maven dependencies often need to be explicitly referenced, as they are not automatically bundled into your library.) +1. Reference any Android binding dependencies by adding an `@(AndroidMavenLibrary)` item to _template/sample/MauiSample.csproj_ for each maven dependency being bound in your native Android project. This will enable Java dependency verification for your project and cause subsequent builds to produce build warnings or errors for missing dependencies. You can address these warnings/errors by adding `@(AndroidMavenLibrary)` or `@(PackageReference)` elements as suggested to satisfy the java dependency chain for the native library you are binding. (Note: The gradle/maven dependencies often need to be explicitly referenced, as they are not automatically bundled into your library.) ```xml - ``` -For more information about this process, see the [AndroidMavenLibrary reference](/dotnet/android/binding-libs/advanced-concepts/android-maven-library) documentation. +See also the [AndroidMavenLibrary reference](/dotnet/android/binding-libs/advanced-concepts/android-maven-library) and [Java dependency verification](dotnet/android/binding-libs/advanced-concepts/java-dependency-verification) documentation for more information about this process. > [!NOTE] > You can rename the placeholder ```DotnetNewBinding``` class to better reflect the native library being wrapped. For more examples and tips for writing the API definitions, read more in the section below: [Modify an existing binding](#modify-an-existing-binding). diff --git a/docs/maui/native-library-interop/index.md b/docs/maui/native-library-interop/index.md index d9d88c2c2..ea3cff96a 100644 --- a/docs/maui/native-library-interop/index.md +++ b/docs/maui/native-library-interop/index.md @@ -41,14 +41,6 @@ Part of this includes orchestrating parts of the build process through MSBuild i - Moving the requisite native artifacts to the expected working directory - Generating the API definition for the binding library project -The binding build process is extended to obtain and build native SDK dependencies by adding the `CommunityToolkit.Maui.NativeLibraryInterop.BuildTasks` NuGet package to your binding project: - -```xml - - - -``` - Android binding projects will add a `@(AndroidGradleProject)` item that points to a build.gradle file that will be used to build the gradle project: ```xml From 204353723cd3e3c2e34564eb98a6f0203f395128 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Mon, 11 Nov 2024 16:11:59 -0800 Subject: [PATCH 11/12] Fix new docs links --- docs/maui/native-library-interop/get-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index 42582af65..eec10d0a1 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -103,7 +103,7 @@ Back on the .NET side, we are now ready to interop with the native library: 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _template/macios/NewBinding.MaciOS.Binding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/sharpie-out/ApiDefinitions.cs_. 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. -See also the [objective-sharpie](previous-versions/xamarin/cross-platform/macios/binding/objective-sharpie/tools) documentation to learn more about this tool. +See also the [objective-sharpie](/previous-versions/xamarin/cross-platform/macios/binding/objective-sharpie/tools) documentation to learn more about this tool. #### API Definition: Android @@ -123,7 +123,7 @@ Back on the .NET side, we are now ready to interop with the native library: ``` -See also the [AndroidMavenLibrary reference](/dotnet/android/binding-libs/advanced-concepts/android-maven-library) and [Java dependency verification](dotnet/android/binding-libs/advanced-concepts/java-dependency-verification) documentation for more information about this process. +See also the [AndroidMavenLibrary reference](/dotnet/android/binding-libs/advanced-concepts/android-maven-library) and [Java dependency verification](/dotnet/android/binding-libs/advanced-concepts/java-dependency-verification) documentation for more information about this process. > [!NOTE] > You can rename the placeholder ```DotnetNewBinding``` class to better reflect the native library being wrapped. For more examples and tips for writing the API definitions, read more in the section below: [Modify an existing binding](#modify-an-existing-binding). From 06cb120371af03329de973ad56540281a8af295e Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 17 Dec 2024 19:30:40 -0500 Subject: [PATCH 12/12] Apply feedback --- docs/maui/native-library-interop/get-started.md | 4 ++-- docs/maui/native-library-interop/index.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/maui/native-library-interop/get-started.md b/docs/maui/native-library-interop/get-started.md index eec10d0a1..7f0c8a68e 100644 --- a/docs/maui/native-library-interop/get-started.md +++ b/docs/maui/native-library-interop/get-started.md @@ -100,14 +100,14 @@ Back on the .NET side, we are now ready to interop with the native library: ``` sharpie bind --output=sharpie-out --namespace=NewBindingMaciOS --sdk=iphoneos18.0 --scope=Headers Headers/NewBinding-Swift.h ``` - 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _template/macios/NewBinding.MaciOS.Binding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/sharpie-out/ApiDefinitions.cs_. + 1. Update the contents of _template/macios/NewBinding.MaciOS.Binding/ApiDefinition.cs_ by replacing it with the contents of _template/macios/NewBinding.MaciOS.Binding/bin/Debug/net9.0-ios/NewBinding.MaciOS.Binding.resources/NewBindingiOS.xcframework/ios-arm64/NewBinding.framework/sharpie-out/ApiDefinitions.cs_ and tweaking as desired (e.g. naming). 1. Run `dotnet build` from _template/macios/NewBinding.MaciOS.Binding_ again. See also the [objective-sharpie](/previous-versions/xamarin/cross-platform/macios/binding/objective-sharpie/tools) documentation to learn more about this tool. #### API Definition: Android -On the native side, make updates in _template/android/native/app/src/main/java/com/example/newbinding/DotnetNewBinding.java_: +On the native side, make updates in _template/android/native/newbinding/src/main/java/com/example/newbinding/DotnetNewBinding.java_: 1. Add an import statement to import the native library you just added. 1. Write the API definitions for the native library APIs of interest. diff --git a/docs/maui/native-library-interop/index.md b/docs/maui/native-library-interop/index.md index ea3cff96a..9a7dbb325 100644 --- a/docs/maui/native-library-interop/index.md +++ b/docs/maui/native-library-interop/index.md @@ -73,7 +73,7 @@ Android binding projects generate the API definition automatically taking into a ![Conceptual overview: NativeLibraryInterop for Android](../images/native-library-interop/nativelibraryinterop-conceptual-overview-android.png "Conceptual overview of NativeLibraryInterop for Android") -An iOS binding library project must include an explicitly defined API. To help with this, [Objective-Sharpie](/xamarin/cross-platform/macios/binding/objective-sharpie/#overview) must be run on the resulting native framework to produce an [API definition file](/xamarin/cross-platform/macios/binding/objective-c-libraries?tabs=macos#The_API_definition_file) (ApiDefinition.cs) alongside it. This can serve as a helpful reference when creating and maintaining the ApiDefintion.cs file used by the iOS binding project. +An iOS binding library project must include an explicitly defined API. To help with this, [Objective-Sharpie](/xamarin/cross-platform/macios/binding/objective-sharpie/#overview) must be run on the resulting native framework to produce an [API definition file](/xamarin/cross-platform/macios/binding/objective-c-libraries?tabs=macos#The_API_definition_file) (ApiDefinition.cs) alongside it. This serves as a helpful reference when creating and maintaining the ApiDefinition.cs file used by the iOS binding project. ![Conceptual overview: NativeLibraryInterop for iOS](../images/native-library-interop/nativelibraryinterop-conceptual-overview-ios.png "Conceptual overview of NativeLibraryInterop for iOS")