@@ -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+
3683task 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