Skip to content

Commit 6cb3cd1

Browse files
committed
Adding build script and Parse License info to GoogleSignIn plugin.
Also fixed some minor issues found due to last minute code review changes that affected the build. Change-Id: I6a4408ed4be073fb11d5bd66a0da21eefdee1d2b
1 parent 2a89edd commit 6cb3cd1

File tree

7 files changed

+267
-13
lines changed

7 files changed

+267
-13
lines changed

GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static void AddDependencies() {
8383
{ "bitcodeEnabled", false },
8484
});
8585
}
86+
#else
87+
static void AddDependencies() { }
8688
#endif // UNITY_ANDROID / iOS
8789
}
8890
}

GoogleSignInPlugin/Assets/GoogleSignIn/GoogleSignIn.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515
// </copyright>
16+
1617
namespace Google {
1718
using System;
1819
using System.Runtime.Serialization;
1920
using System.Threading.Tasks;
2021
using Google.Impl;
22+
using UnityEngine;
2123

2224
/// <summary>
2325
/// Google sign in API.
@@ -89,8 +91,9 @@ public static GoogleSignIn DefaultInstance {
8991
theInstance = new GoogleSignIn(new GoogleSignInImpl(Configuration));
9092
#else
9193
theInstance = new GoogleSignIn(null);
92-
throw new SignInException(StatusCode.DeveloperError,
93-
"This platform is not supported by GoogleSignIn");
94+
throw new SignInException(
95+
GoogleSignInStatusCode.DeveloperError,
96+
"This platform is not supported by GoogleSignIn");
9497
#endif
9598
}
9699
return theInstance;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
BSD License
2+
3+
For Parse .NET SDK software
4+
5+
Copyright (c) 2015-present, Parse, LLC. All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* Neither the name Parse nor the names of its contributors may be used to
18+
endorse or promote products derived from this software without specific
19+
prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

GoogleSignInPlugin/Assets/Parse/LICENSE.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoogleSignInPlugin/Assets/SignInSample/SigninSampleScript.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ public class SigninSampleScript : MonoBehaviour {
2727

2828
public string webClientId = "<your client id here>";
2929

30-
private static readonly GoogleSignInConfiguration configuration =
31-
new GoogleSignInConfiguration {
32-
WebClientId = webClientId,
33-
RequestIdToken = true
34-
};
30+
private GoogleSignInConfiguration configuration;
31+
32+
// Defer the configuration creation until Awake so the web Client ID
33+
// Can be set via the property inspector in the Editor.
34+
void Awake() {
35+
configuration = new GoogleSignInConfiguration {
36+
WebClientId = webClientId,
37+
RequestIdToken = true
38+
};
39+
}
3540

3641
public void OnSignIn() {
3742
GoogleSignIn.Configuration = configuration;

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ or as part of Firebase configuration.
2020
In order to access ID tokens or server auth codes, you also need to configure
2121
a web client ID.
2222

23-
## Building the Android AAR library
24-
To build the Android library needed by the Unity plugin, run
25-
`gradlew :native-googlesignin:assembleDebug` (or assembleRelease).
26-
27-
Copy the aar file in native-googlesignin/build/outputs/aar to Assets/Plugins/Android.
28-
23+
## Building the Plugin
24+
To build the plugin run `./gradlew build_all`. This builds the support aar
25+
library, and packages the plugin into a .unitypackage file. It also packages the
26+
sample scene and script in a separate package.
2927

3028
__TODO:__ How to use this plugin with Firebase Auth.
3129

build.gradle

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,214 @@ allprojects {
3333
}
3434
}
3535

36+
project.ext {
37+
// Determine the current OS.
38+
os_name = System.getProperty("os.name").toLowerCase();
39+
os_osx = os_name.contains("mac os x");
40+
os_windows = os_name.contains("windows");
41+
os_linux = os_name.contains("linux");
42+
43+
unity_exe = System.getProperty("UNITY_EXE")
44+
if (unity_exe == null || unity_exe.isEmpty()) {
45+
unity_exe = System.getenv("UNITY_EXE")
46+
}
47+
if (unity_exe == null || unity_exe.isEmpty()) {
48+
if (os_osx) {
49+
unity_exe = '/Applications/Unity/Unity.app/Contents/MacOS/Unity'
50+
} else if (os_windows) {
51+
unity_exe = 'c:\\program files\\unity\\editor\\unity.exe'
52+
} else {
53+
// Fallback to just unity, and expect it on the path.
54+
unity_exe = 'unity'
55+
}
56+
}
57+
58+
git_exe = System.getProperty("GIT_EXE")
59+
if (git_exe == null || git_exe.isEmpty()) {
60+
git_exe = System.getenv("GIT_EXE")
61+
}
62+
if (git_exe == null || git_exe.isEmpty()) {
63+
// Fallback to git and expect it to be on the path.
64+
git_exe = 'git'
65+
}
66+
67+
exportPath = file('GoogleSignIn-1.0.0.unitypackage').absolutePath
68+
samplePath = file('GoogleSignIn-sample.unitypackage').absolutePath
69+
pluginSrcPath = file('GoogleSignInPlugin').absolutePath
70+
pluginProjectPath = file('build/GoogleSignInPlugin').absolutePath
71+
72+
resolverDir = new File('build/jarresolver').absolutePath
73+
jarresolver_uri = System.getProperty("RESOLVER_PACKAGE_URI")
74+
jarresolver_repos = [
75+
'https://github.com/googlesamples/unity-jar-resolver.git'
76+
]
77+
// Set the tag to a specific value if you want to build pinned to a
78+
// specific version of the jar resolver (This is uncommon).
79+
// null indicates HEAD.
80+
jarresolver_tag = null;
81+
}
82+
3683
task clean(type: Delete) {
3784
delete rootProject.buildDir
3885
}
86+
87+
task copy_unity_project() {
88+
doFirst {
89+
copy {
90+
from pluginSrcPath
91+
into pluginProjectPath
92+
}
93+
}
94+
}
95+
96+
task copy_aar() {
97+
dependsOn ':native-googlesignin:assembleDefault', copy_unity_project
98+
doLast {
99+
def destDir = new File(pluginProjectPath + "/Assets/Plugins/Android")
100+
if (!destDir.exists()) {
101+
destDir.mkdirs()
102+
}
103+
def srcDir = file(project(':native-googlesignin').buildDir.absolutePath +
104+
"/outputs/aar")
105+
copy {
106+
from srcDir.absolutePath
107+
into destDir.absolutePath
108+
include "native-googlesignin-release.aar"
109+
}
110+
}
111+
}
112+
113+
114+
task copy_jarresolver() {
115+
description = "Clones the jar resolver project and copied into the build."
116+
doFirst {
117+
if (file(resolverDir).exists()) {
118+
delete resolverDir
119+
}
120+
}
121+
122+
doLast {
123+
// Copy the package if the direct path is given.
124+
if (jarresolver_uri != null) {
125+
mkdir("${resolverDir}")
126+
def resolver = new File("${resolverDir}/resolver.unitypackage")
127+
new URL("${jarresolver_uri}").withInputStream {
128+
inputStream -> resolver.withOutputStream { it << inputStream }
129+
}
130+
return
131+
}
132+
133+
// Else, check each one of the repo addresses and stop when successful.
134+
for (repo in jarresolver_repos) {
135+
def result = exec {
136+
executable "${git_exe}"
137+
args "clone", repo, "${resolverDir}"
138+
ignoreExitValue true
139+
}
140+
if (result.exitValue == 0 && jarresolver_tag != null) {
141+
result = exec {
142+
executable "${git_exe}"
143+
args "checkout", "-b", "buildver", "${jarresolver_tag}"
144+
workingDir "${resolverDir}"
145+
}
146+
}
147+
148+
if (result.exitValue == 0) {
149+
println "Downloaded resolver from " + repo
150+
return
151+
}
152+
}
153+
}
154+
}
155+
156+
task package_plugin () {
157+
description = "Creates and exports the Plugin unity package"
158+
159+
doLast {
160+
def tree = fileTree(resolverDir) {
161+
include "*.unitypackage"
162+
}
163+
def jarresolver_package = tree.getSingleFile()
164+
def argv = [
165+
"-g.building",
166+
// This prevents the VersionHandler to preserve the plugin layout
167+
"-gvh_disable",
168+
// NOTE: This doesn't target Android since we don't want to have
169+
// dependencies on the Jar Resolver as they require the plugin to
170+
// be enabled during the build process which would break the
171+
// versioning process. Compilation is verified when exporting
172+
// the sample projects.
173+
"-batchmode",
174+
"-projectPath", pluginProjectPath,
175+
"-logFile", "build/unity.log",
176+
"-importPackage", jarresolver_package,
177+
"-exportPackage",
178+
"Assets/GoogleSignIn",
179+
"Assets/Parse",
180+
"Assets/PlayServicesResolver",
181+
"Assets/Plugins",
182+
"${exportPath}",
183+
"-quit"
184+
]
185+
186+
ext.execResult = exec {
187+
executable "${unity_exe}"
188+
args argv
189+
ignoreExitValue true
190+
}
191+
if (ext.execResult.exitValue != 0) {
192+
println "***Error Running Unity:"
193+
def src = file('build/unity.log').text
194+
print src
195+
throw new GradleException('error exporting plugin')
196+
}
197+
}
198+
}
199+
200+
201+
task package_sample () {
202+
description = "Creates and exports the Google Sign-in Sample"
203+
204+
doLast {
205+
def argv = [
206+
"-g.building",
207+
// NOTE: This doesn't target Android since we don't want to have
208+
// dependencies on the Jar Resolver as they require the plugin to
209+
// be enabled during the build process which would break the
210+
// versioning process. Compilation is verified when exporting
211+
// the sample projects.
212+
"-batchmode",
213+
"-projectPath", pluginProjectPath,
214+
"-logFile", "build/unity-sample.log",
215+
"-exportPackage",
216+
"Assets/SignInSample",
217+
"${samplePath}",
218+
"-quit"
219+
]
220+
221+
ext.execResult = exec {
222+
executable "${unity_exe}"
223+
args argv
224+
ignoreExitValue true
225+
}
226+
if (ext.execResult.exitValue != 0) {
227+
println "***Error Running Unity:"
228+
def src = file('build/unity-sample.log').text
229+
print src
230+
throw new GradleException('error exporting sample')
231+
}
232+
}
233+
}
234+
235+
/*
236+
* This is a top level task that build the Unity plugin.
237+
* It does the following:
238+
* - copy the java/C++ library to the Plugins directory.
239+
* - Import the latest Play Services Resolver plugin
240+
* - Build the Google Sign-In plugin package (requires Unity).
241+
* - Build the Google Sign-In Sample package (requires Unity).
242+
*/
243+
task build_all() {
244+
dependsOn copy_aar, copy_jarresolver, package_plugin, package_sample
245+
}
246+

0 commit comments

Comments
 (0)