• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..16-Nov-2021-

README.mdH A D16-Nov-20214.3 KiB10478

build_native_ext_for_android.shH A D16-Nov-20211.8 KiB5417

build_native_ext_for_ios.shH A D16-Nov-20212.4 KiB6934

README.md

1This directory contains useful resources for getting gRPC C# to work on
2platforms that are not yet fully supported.
3
4# Xamarin
5
6gRPC C# now has experimental support for Xamarin.
7See [HelloworldXamarin](/examples/csharp/HelloworldXamarin) for an example how to use it.
8
9Starting from gRPC C# 2.34.x: in addition to the regular `Grpc.Core` dependency, you will also
10need to add `Grpc.Core.Xamarin` dependency to your project (which has the mobile-specific builds of c# native extension library).
11The `Grpc.Core` and `Grpc.Core.Xamarin` package versions must always match exactly for things to work.
12Also note that the `Grpc.Core.Xamarin` needs to be added to your `*.Android` and `*.iOS` projects
13in order for the native library bindings to be registered correctly (see https://github.com/grpc/grpc/issues/16250).
14
15What's currently supported:
16
17Xamarin.Android
18- supported API level: Kitkat 4.4+ (= API level 19)
19- supported ABIs: `armeabi-v7a` (vast majority of Android devices out there),
20  `arm64-v8a` (some newer Android devices), `x86` (for emulator)
21
22Xamarin.iOS
23- supported architectures: armv7, arm64 (iPhone 6+) and x86_64 (iPhone simulator)
24
25# Unity
26
27gRPC C# now has experimental support for Unity. Please try using gRPC with
28Unity and provide feedback!
29
30How to test gRPC in a Unity project
31
321. Create a Unity project that targets .NET 4.x Equivalent (Edit -> Project Settings -> Player -> Configuration -> Scripting Runtime Version). gRPC uses APIs that are only available in .NET4.5+ so this is a requirement.
33
342. Download the latest development build of `grpc_unity_package.VERSION.zip` from
35   [daily builds](https://packages.grpc.io/)
36
373. Extract the `.zip` file in the `Assets` directory in your Unity project
38
394. Unity IDE will pick up all the bundled files and add them to project automatically.
40   You should be able to use gRPC and Protobuf in your scripts from now on.
41
425. (optional) Extra steps for iOS, see below
43
44What's currently bundled in the `grpc_unity_package`
45-  Grpc.Core and its dependencies
46-  Google.Protobuf
47-  Precompiled native libraries for Linux, MacOS, Windows, Android and iOS.
48
49Please note that `Grpc.Core` is now in maintenance mode (see [The future of gRPC in C# belongs to grpc-dotnet](https://grpc.io/blog/grpc-csharp-future/)). There is a plan to support Unity in `Grpc.Net.Client`, which depends on Unity's .NET 5 or .NET 6 support. See [this issue](https://github.com/grpc/grpc-dotnet/issues/1309) for more information.
50
51## Building for iOS
52
53To build a Unity app on iOS, there are extra steps to do to make it work:
54
551. Add a `Assets/link.xml` asset file to your Unity project with the following content:
56   ```xml
57   <linker>
58       <assembly fullname="UnityEngine">
59          <type fullname="UnityEngine.Application" preserve="fields">
60               <property name="platform"/>
61           </type>
62       </assembly>
63   </linker>
64   ```
65   If you don't, you might encounter the following error: `System.IO.FileNotFoundException: Error loading native library. Not found in any of the possible locations:` with a list of paths that point to the `libgrpc_csharp_ext.x64.dylib` file.
662. Due to the growing build size, bitcode has been disabled for the gRPC library. You must disable it in your XCode project as well.
673. Add the `libz` framework.
68
69Steps 2 and 3 can be automated by adding the following `Assets/Scripts/BuildIos.cs` script in your Unity project, and attaching it to a Unity game object:
70
71```cs
72#if UNITY_EDITOR && UNITY_IOS
73using System.IO;
74using UnityEngine;
75using UnityEditor;
76using UnityEditor.Callbacks;
77using UnityEditor.iOS.Xcode;
78
79public class BuildIos
80{
81  [PostProcessBuild]
82  public static void OnPostProcessBuild(BuildTarget target, string path)
83  {
84    var projectPath = PBXProject.GetPBXProjectPath(path);
85    var project = new PBXProject();
86    project.ReadFromString(File.ReadAllText(projectPath));
87#if UNITY_2019_3_OR_NEWER
88    var targetGuid = project.GetUnityFrameworkTargetGuid();
89#else
90    var targetGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName());
91#endif
92
93    // libz.tbd for grpc ios build
94    project.AddFrameworkToProject(targetGuid, "libz.tbd", false);
95
96    // bitode is disabled for libgrpc_csharp_ext, so need to disable it for the whole project
97    project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
98
99    File.WriteAllText(projectPath, project.WriteToString());
100  }
101}
102#endif
103```
104