@@ -54,13 +54,12 @@ the Google Repository SDK components. These are found in the "extras" section.
54
54
55
55
# Packaging
56
56
57
- The plugin consists of a C# DLL that contains the logic to resolve the dependencies
58
- and the logic to resolve dependencies and copy them into Unity projects.
59
- This includes removing older versions of the client libraries.
57
+ The plugin consists of several C# DLLs that contain
58
+ the logic to resolve the dependencies for both Android and iOS (using CocoaPods),
59
+ the logic to resolve dependencies and copy them into Unity projects, and logic
60
+ to remove older versions of the client libraries as well as older versions of the
61
+ JarResolver DLLs.
60
62
61
- There also are 2 C# files. The first, PlayServicesResolver.cs,
62
- creates an AssetPostprocessor instance that is used to trigger background
63
- resolution of the dependencies. It also adds a menu item
64
63
(Assets/Google Play Services/Resolve Client Jars). In order to support
65
64
Unity version 4.x, this class also converts the aar file
66
65
to a java plugin project. The second C# file is SampleDependencies.cs
@@ -76,19 +75,45 @@ plugin).
76
75
2 . Copy the SampleDependencies.cs file to another name specific to your plugin
77
76
and add the dependencies your plugin needs.
78
77
78
+ Reflection is used to access the resolver in order to behave correctly when the
79
+ project is being loaded into Unity and there is no specific order of class
80
+ initialization.
81
+
82
+ For Android dependencies first create and instance of the resolver object:
79
83
```
80
- instance.DependOn(group, artifact, version);
84
+ // Setup the resolver using reflection as the module may not be
85
+ // available at compile time.
86
+ Type playServicesSupport = Google.VersionHandler.FindClass(
87
+ "Google.JarResolver", "Google.JarResolver.PlayServicesSupport");
88
+ if (playServicesSupport == null) {
89
+ return;
90
+ }
91
+ svcSupport = svcSupport ?? Google.VersionHandler.InvokeStaticMethod(
92
+ playServicesSupport, "CreateInstance",
93
+ new object[] {
94
+ "GooglePlayGames",
95
+ EditorPrefs.GetString("AndroidSdkRoot"),
96
+ "ProjectSettings"
97
+ });
81
98
```
82
99
83
- This declares that the this application now depends on the specified artifact.
84
- Where:
85
-
86
- * group: indicates the artifact group, e.g. "com.android.support" or
87
- "com.google.android.gms"
88
- * artifact: indicates the artifact, e.g. "appcompat-v7" or
89
- "play-services-appinvite"
90
- * version: indicates the version. The version value supports both specific
91
- versions such as 8.1.0, and also the trailing '+' indicating "or greater" for
100
+ Then add dependencies. For example to depend on
101
+ play-services-games version 9.6.0, you need to specify the package, artifact,
102
+ and version as well as the packageId from the SDK manager in case a updated
103
+ version needs to be downloaded from the SDK Manager in order to build.
104
+ ```
105
+ Google.VersionHandler.InvokeInstanceMethod(
106
+ svcSupport, "DependOn",
107
+ new object[] {
108
+ "com.google.android.gms",
109
+ "play-services-games",
110
+ "9.6.0" },
111
+ namedArgs: new Dictionary<string, object>() {
112
+ {"packageIds", new string[] { "extra-google-m2repository" } }
113
+ });
114
+ ```
115
+ The version value supports both specific versions such as 8.1.0,
116
+ and also the trailing '+' indicating "or greater" for
92
117
the portion of the number preceding the period. For example 8.1.+ would match
93
118
8.1.2, but not 8.2. The string "8+" would resolve to any version greater or
94
119
equal to 8.0. The meta version 'LATEST' is also supported meaning the greatest
@@ -101,6 +126,39 @@ are processed by the Android Gradle plugin. Unfortunately, Unity does not perfo
101
126
the same processing, so this plugin handles known cases of this variable substition
102
127
by exploding the aar and replacing ${applicationId} with the bundleID.
103
128
129
+
130
+ # iOS Dependency Management
131
+ iOS dependencies are identified using Cocoapods. Cocoapods is run as a post build
132
+ process step. The libraries are downloaded and injected into the XCode project
133
+ file directly, rather than creating a separate xcworkspace.
134
+
135
+ To add a dependency you first need an instance of the resolver. Reflection is
136
+ used to safely handle race conditions when Unity is loading the project and the
137
+ order of class initialization is not known.
138
+ ```
139
+ Type iosResolver = Google.VersionHandler.FindClass(
140
+ "Google.IOSResolver", "Google.IOSResolver");
141
+ if (iosResolver == null) {
142
+ return;
143
+ }
144
+ ```
145
+
146
+ Dependencies for iOS are added by referring to CocoaPods. The libraries and
147
+ frameworks are added to the Unity project, so they will automatically be included.
148
+
149
+ This example add the GooglePlayGames pod, version 5.0 or greater,
150
+ disabling bitcode generation.
151
+
152
+ ```
153
+ Google.VersionHandler.InvokeStaticMethod(
154
+ iosResolver, "AddPod",
155
+ new object[] { "GooglePlayGames" },
156
+ namedArgs: new Dictionary<string, object>() {
157
+ { "version", "5.0+" },
158
+ { "bitcodeEnabled", false },
159
+ });
160
+ ```
161
+
104
162
# Disabling automatic resolution
105
163
106
164
Automatic resolution can be disabled in the Settings dialog,
@@ -132,9 +190,11 @@ non-concrete version constraints (i.e. have a + in the version).
132
190
3. If there
133
191
4. If there are still possible versions to check, add the dependency to the end
134
192
of the unresolved list for re-processing with a new version candidate.
135
- 5. If there are no possible versions to resolve both the candidate and the
193
+ 5. If there are no possible versions, then the SDK Manager is used to download
194
+ and updated versions of the libraries based on the packageId.
195
+ 6. If there still are no possible versions to resolve both the candidate and the
136
196
unresolved dependencies, then either fail resolution with an exception, or use
137
- the greatest version value (depending on the useLatest flag passed to resolve) .
197
+ the greatest version value.
138
198
3. When a candidate version is selected, the pom file is read for that version and
139
199
the
140
200
@@ -143,4 +203,3 @@ the unresolved.
143
203
3 . Process transitive dependencies
144
204
5 . for each candidate artifact, read the pom file for dependencies and add them to
145
205
the unresolved list.
146
-
0 commit comments