Skip to content

Commit c7b5eda

Browse files
committed
Adding the C# and build code for the PlayServices jar resolver.
This adds the support for 4.x aar conversion, and updates the README instructions to make it easier to consume. Change-Id: I6e26bd67b005a38c20dca6b869fc1b43b48a21bd
1 parent 50339db commit c7b5eda

15 files changed

+877
-91
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
build/
2+
3+
.gradle/
4+
5+
plugin/Assembly-CSharp-Editor.csproj
6+
plugin/Assets/PlayServicesResolver/Editor/JarResolverLib.dll
7+
plugin/Assets/Plugins/
8+
plugin/Assets/Plugins.meta
9+
plugin/Assets/StyleCop.Cache
10+
plugin/Assets/StyleCop.Cache.meta
11+
plugin/Library/
12+
plugin/ProjectSettings/
13+
plugin/Temp/
14+
plugin/obj/
15+
plugin/plugin.sln
16+
17+

README.md

Lines changed: 25 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,41 @@ libraries included in the Unity project.
1111
With this library, a plugin declares the dependencies needed and these are
1212
resolved by using the play-services and support repositories that are part of
1313
the Android SDK. These repositories are used to store .aar files in a Maven
14-
(Gradle) compatible repository.
14+
(Gradle) compatible repository.
1515

1616
This library implements a subset of the resolution logic used by these build
1717
tools so the same functionality is available in Unity.
1818

1919
# Requirements
2020

21-
This library only works with Unity version 5.0 or better.
21+
This library only works with Unity version 4.6.8 or higher.
2222

2323
The library relies on the installation of the Android Support Repository and
2424
the Google Repository SDK components. These are found in the "extras" section.
2525

2626
# Packaging
2727

28-
The library is packaged as a DLL which implements a Unity editor extension.
29-
The library contains no runtime components.
28+
The plugin consists of a C# DLL that contains the logic to resolve the dependencies
29+
and the logic to resolve dependencies and copy them into Unity projects.
30+
This includes removing older versions of the client libraries.
3031

31-
There is sample code demonstrating how to declare dependencies and trigger
32-
resolution both from the menu, and as a background process when assets change.
32+
There also are 2 C# files. The first, PlayServicesResolver.cs,
33+
creates an AssetPostprocessor instance that is used to trigger background
34+
resolution of the dependencies. It also adds a menu item
35+
(Assets/Google Play Services/Resolve Client Jars). In order to support
36+
Unity version 4.x, this class also converts the aar file
37+
to a java plugin project. The second C# file is SampleDependencies.cs
38+
which is the model for plugin developers to copy and add the specific
39+
dependencies needed.
3340

34-
# Usage
35-
36-
1. Copy the file [JarResolverLib.dll](Assets/Editor/JarResolver.dll) to the Assets/Editor folder in your Unity
37-
project.
38-
39-
The dependency information is stored statically, so all plugins register their
40-
dependency in a common location. In the worse case, this results in multiple calls to
41-
resolve the dependencies, but they all get the same resolution outcome.
41+
During resolution, all the dependencies from all the plugins are merged and resolved.
4242

43-
2. Create an instance of PlayServicesSupport. Pass in a name for the
44-
client (needs to use valid filename characters), the path to the Android SDK,
45-
and the path to the settings directory. For Unity, this is "ProjectSettings".
46-
47-
```
48-
PlayServicesSupport instance = PlayServicesSupport.CreateInstance("myPlugin",
49-
EditorPrefs.GetString("AndroidSdkRoot"),
50-
"ProjectSettings");
51-
```
43+
# Usage
44+
1. Add the unitypackage to your plugin project (assuming you are developing a
45+
plugin).
5246

53-
3. Specify the dependencies for your plugin. In your editor script, add a line
54-
for each direct dependency:
47+
2. Copy the SampleDependencies.cs file to another name specific to your plugin
48+
and add the dependencies your plugin needs.
5549

5650
```
5751
instance.DependOn(group, artifact, version);
@@ -71,69 +65,16 @@ the portion of the number preceding the period. For example 8.1.+ would match
7165
equal to 8.0. The meta version 'LATEST' is also supported meaning the greatest
7266
version available, and "0+" indicates any version.
7367

68+
# How it works
69+
7470
When the dependency is added, the maven-metadata.xml file is read for this
7571
dependency. If there are no versions available (or the dependency is not
7672
found), there is an exception thrown. When the metadata is read, the list of
7773
known versions is filtered based on the version constraint. The remaining list
78-
of version is known as <em>possible versions</em>.
79-
80-
The greatest value of the possible versions is known as the <em>best version</em>. The best version is what is used to perform resolution.
81-
82-
2. Call Resolve. In your editor script call:
83-
84-
```
85-
PlayServicesSupport.ResolveDependencies(useLatest);
86-
```
87-
88-
Performs resolution of the dependencies. The parameter useLatest, if true,
89-
causes the latest version of any dependency to be used in the case of a
90-
conflict. If this flag is false, the resolution will fail by throwing an
91-
exception indicating the dependencies cannot be resolved.
92-
93-
The return value is a dictionary of dependencies needed. The key is the
94-
"versionless" key of the dependency, and the value is the Dependency object.
95-
96-
3. Copy/Update the dependencies in your project. Once ResolveDependencies
97-
returns, you need to copy and update the dependencies in your project. To do
98-
this, call
99-
100-
```
101-
PlayServicesSupport.CopyDependencies(
102-
103-
deps, "Assets/Plugins/Android", confirm);
104-
```
105-
106-
Where:
74+
of version is known as <em>possible versions</em>.
10775

108-
* <strong>deps</strong> is the dictionary returned from ResolveDependencies
109-
* <strong>"Assets/Plugins/Android" </strong>is the project relative path of where to copy the client libraries.
110-
* <strong>confirm</strong> is a delegate of type PlayServicesSupport.OverwriteConfirmation which is
111-
called when an a dependency already exists in the project. The delegate should
112-
return true to have the old dependency be overwritten by the new.
113-
114-
The signature of PlayServicesSupport.OverwriteConfirmation is
115-
116-
```
117-
bool OverwriteConfirmation (Dependency oldDep, Dependency newDep)
118-
```
119-
120-
# Calling resolution from the menu
121-
122-
If you want to make the resolution process manually started from the menu, you
123-
can use this class as a starter. It declares the dependencies statically (so
124-
other library clients will resolve them as well), and adds a menu item to
125-
perform resolution and copy the results. See
126-
[ManualResolution](Assets/Editor/ManualResolution.cs)
127-
128-
# Calling resolution in the background
129-
130-
If you want to make the resolution process automatically started when there is
131-
a change to the assets, you can kick off the process by implementing an
132-
AssetPostprocessor. See
133-
134-
[BackgroundResolution](Assets/Editor/BackgroundResolution.cs)
135-
136-
# How Resolution works
76+
The greatest value of the possible versions is known as the <em>best version</em>.
77+
The best version is what is used to perform resolution.
13778

13879
Resolution is done by following the steps:
13980

@@ -154,18 +95,11 @@ of the unresolved list for re-processing with a new version candidate.
15495
unresolved dependencies, then either fail resolution with an exception, or use
15596
the greatest version value (depending on the useLatest flag passed to resolve).
15697
3. When a candidate version is selected, the pom file is read for that version and
157-
the
98+
the
15899

159100
4. If there is a candidate version, add it to the candidate list and remove from
160101
the unresolved.
161102
3. Process transitive dependencies
162103
5. for each candidate artifact, read the pom file for dependencies and add them to
163104
the unresolved list.
164105

165-
# Code location and building instructions
166-
167-
There are 3 assemblies that are part of the solution.
168-
169-
1. The Unity Editor UI components
170-
2. The Jar resolver library
171-
3. The unit tests.

build.gradle

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* Gradle file to build the Unity plugin for Google Play Game Services.
3+
*/
4+
5+
buildscript {
6+
repositories {
7+
jcenter()
8+
mavenLocal()
9+
}
10+
}
11+
12+
/*
13+
Project level variables
14+
*/
15+
project.ext {
16+
sdk_root = System.getProperty("ANDROID_HOME")
17+
if (sdk_root == null || sdk_root.isEmpty()) {
18+
sdk_root = System.getenv("ANDROID_HOME")
19+
}
20+
unity_exe = System.getProperty("UNITY_EXE")
21+
if (unity_exe == null || unity_exe.isEmpty()) {
22+
unity_exe = System.getenv("UNITY_EXE")
23+
}
24+
if (unity_exe == null || unity_exe.isEmpty()) {
25+
unity_exe ='/Applications/Unity/Unity.app/Contents/MacOS/Unity'
26+
}
27+
28+
mdtool_exe = System.getProperty("MDTOOL_EXE")
29+
if (mdtool_exe == null || mdtool_exe.isEmpty()) {
30+
mdtool_exe = System.getenv("MDTOOL_EXE")
31+
}
32+
if (mdtool_exe == null || mdtool_exe.isEmpty()) {
33+
mdtool_exe ='/Applications/Xamarin Studio.app/Contents/MacOS/mdtool'
34+
}
35+
36+
pluginSrc = file('plugin').absolutePath
37+
pluginProj = file('build/PluginSrc').absolutePath
38+
buildPath = file('build').absolutePath
39+
exportPath = file('build/plugin.unitypackage').absolutePath
40+
currentPluginPath = file('.').absolutePath
41+
currentPluginName = 'play-services-resolver-0.1.unitypackage'
42+
}
43+
44+
if (!tasks.findByName('prebuild')) {
45+
task prebuild() {
46+
println('Local prebuild')
47+
}
48+
prebuild.dependsOn {
49+
project.tasks.findAll { task -> task.ext.has('remoteTaskPhase') && task.ext.remoteTaskPhase == 'prebuild' }
50+
}
51+
}
52+
if (!tasks.findByName('build')) {
53+
task build() {
54+
println('Local build')
55+
}
56+
build.dependsOn {
57+
project.tasks.findAll { task -> task.ext.has('remoteTaskPhase') && task.ext.remoteTaskPhase == 'build' }
58+
}
59+
}
60+
if (!tasks.findByName('postbuild')) {
61+
task postbuild() {
62+
println('Local postbuild')
63+
}
64+
postbuild.dependsOn {
65+
project.tasks.findAll { task -> task.ext.has('remoteTaskPhase') && task.ext.remoteTaskPhase == 'postbuild' }
66+
}
67+
}
68+
69+
project.defaultTasks = ['prebuild', 'build', 'postbuild']
70+
71+
72+
/**
73+
Final task of building all the unity packages.
74+
**/
75+
task unity_package(dependsOn:'export_package') {
76+
77+
description = "Top level task for building the unity packages"
78+
79+
doLast {
80+
println "Packaging Complete!"
81+
}
82+
83+
// Mark this a build phase task for remoteTask support.
84+
ext.remoteTaskPhase = 'build'
85+
86+
// Depends on packaging all the samples
87+
dependsOn {
88+
tasks.findAll { task -> task.name.startsWith('PackageSample') }
89+
}
90+
}
91+
92+
task export_package () {
93+
description = "Creates and exports the Plugin unity package"
94+
95+
doLast {
96+
def argv = [
97+
"-g.building",
98+
"-buildTarget",
99+
"android",
100+
"-batchmode",
101+
"-projectPath",
102+
"${pluginProj}",
103+
"-logFile",
104+
"build/unity.log",
105+
"-exportPackage",
106+
"Assets/PlayServicesResolver",
107+
"${exportPath}",
108+
"-quit"
109+
]
110+
exec {
111+
executable "${unity_exe}"
112+
args argv
113+
}
114+
}
115+
}
116+
export_package.ext.remoteTaskPhase = 'build'
117+
118+
/*
119+
Copy the plugin to the current-build directory
120+
*/
121+
task copy_plugin() {
122+
description = 'Copy plugin to the current-build directory'
123+
doFirst {
124+
copy {
125+
from file(exportPath)
126+
into file(currentPluginPath)
127+
rename ('plugin.unitypackage', currentPluginName)
128+
}
129+
}
130+
131+
doLast {
132+
println "Copied ${exportPath} to ${currentPluginPath}"
133+
}
134+
135+
ext.remoteTaskPhase = 'postbuild'
136+
137+
}
138+
139+
140+
task copy_plugin_source << {
141+
copy {
142+
from {"${pluginSrc}"}
143+
into {"${pluginProj}"}
144+
}
145+
}
146+
copy_plugin_source.description = "Copies plugin source into build directory"
147+
copy_plugin_source.ext.remoteTaskPhase = 'prebuild'
148+
149+
task compile_sharpen(type: org.gradle.api.tasks.Exec) {
150+
doFirst {
151+
println "Running $mdtool_exe"
152+
}
153+
workingDir 'source'
154+
commandLine "${mdtool_exe}", '--verbose', 'build'
155+
ext.remoteTaskPhase = 'prebuild'
156+
}
157+
158+
task copy_csharp_dll() << {
159+
copy {
160+
from "source/JarResolverLib/bin/Debug/JarResolverLib.dll"
161+
into "${buildDir}/PluginSrc/Assets/PlayServicesResolver/Editor"
162+
}
163+
}
164+
copy_csharp_dll.dependsOn compile_sharpen
165+
copy_csharp_dll.ext.remoteTaskPhase = 'prebuild'
166+

gradle/wrapper/gradle-wrapper.jar

50.9 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Dec 01 12:11:27 PST 2015
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip

0 commit comments

Comments
 (0)